Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

先把字符串倒排序,然后5个for~~~

Posted by 2004140022 at 2015-10-13 10:23:54 on Problem 1248
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
bool cmp(char a,char b)
{
    return a>b;
}
int main()
{
    int a,b,c,d,e,n,l,ans;
    string s;
    int t[5];
    while(1)
    {
        scanf("%d",&n);
        cin>>s;
        if(!n&&s=="END")break;
        ans=0;
        l=s.length();
        sort(s.begin(),s.end(),cmp);
       // cout<<s<<endl;
        for(a=0;a<l;a++)
            for(b=0;b<l;b++)
                for(c=0;c<l;c++)
                    for(d=0;d<l;d++)
                        for(e=0;e<l;e++)
                        {
                            if(a!=b&&a!=c&&a!=d&&a!=e&&b!=c&&b!=d&&b!=e&&c!=d&&c!=e&&d!=e)
                            {
                                t[0]=s[a]-'A'+1;
                                t[1]=s[b]-'A'+1;
                                t[2]=s[c]-'A'+1;
                                t[3]=s[d]-'A'+1;
                                t[4]=s[e]-'A'+1;
                                int tmp=t[0]-t[1]*t[1]+t[2]*t[2]*t[2]-t[3]*t[3]*t[3]*t[3]+t[4]*t[4]*t[4]*t[4]*t[4];
                                if(tmp==n)
                                {
                                    printf("%c%c%c%c%c\n",s[a],s[b],s[c],s[d],s[e]);
                                    ans=1;
                                    goto TAR;
                                }
                            }

                        }
        TAR:
                        if(!ans)
                        puts("no solution");
    }

return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator