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 |
又被坑了,代码#include<iostream> using namespace std; #include<algorithm> #include<string.h> /*bool compare(char a,char b) { return a>b; }*/ int main() { long target; char s[14],ch; int j,i,k,l,m,n,leap; int a[14]; while(cin>>target>>s) { l=strlen(s); leap=0; sort(s,s+l); //cout<<s<<" "<<endl; if(target==0&&l==3) { break; } for(i=0;i<l;i++) { a[i]=(int)s[i]-64; //cout<<a[i]<<" "<<s[i]<<" "; } for(i=l-1;i>=0;i--) { for(j=l-1;j>=0;j--) { for(k=l-1;k>=0;k--) { for(m=l-1;m>=0;m--) { for(n=l-1;n>=0;n--) { /* cout<<a[i]<<endl; cout<<a[j]*a[j]<<endl; cout<<a[k]*a[k]*a[k]<<endl; cout<<a[m]*a[m]*a[m]*a[m]<<endl; cout<<a[n]*a[n]*a[n]*a[n]*a[n]<<endl;*/ if(i==j||i==k||i==m||i==n||j==k||j==m||j==n||k==m||k==n||m==n)continue; if(a[i]-a[j]*a[j]+a[k]*a[k]*a[k]-a[m]*a[m]*a[m]*a[m]+a[n]*a[n]*a[n]*a[n]*a[n]==target) { cout<<s[i]<<s[j]<<s[k]<<s[m]<<s[n]<<endl; leap=1; break; } } if(leap==1)break; } if(leap==1)break; } if(leap==1)break; } if(leap==1)break; } if(leap!=1) cout<<"no solution"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator