Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
先把字符串倒排序,然后5个for~~~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator