#include<iostream> #include<string> #include<algorithm> #include<functional> #include<cmath> using namespace std; int main(int argc, char *argv[]){ int target; string letters; int v,w,x,y,z; while(cin>>target>>letters,target){ char *cp= new char[letters.length()+1]; letters.copy(cp,letters.length(),0); *(cp+letters.length())='\0'; sort(cp,cp+letters.length(),greater<int>()); for(int i=0;i<letters.length();i++){ v=cp[i]-64; for(int j=0;j<letters.length();j++){ w=cp[j]-64; if(w==v){ continue; } for(int k=0;k<letters.length();k++){ x=cp[k]-64; if(x==w||x==v){ continue; } for(int m=0;m<letters.length();m++){ y=cp[m]-64; if(y==x||y==w||y==v){ continue; } for(int n=0;n<letters.length();n++){ z=cp[n]-64; if(z==y||z==x||z==w||z==v){ continue; } if(target==pow(1.0*v,1)-pow(1.0*w,2)+pow(1.0*x,3)-pow(1.0*y,4)+pow(1.0*z,5)){ cout<<cp[i]<<cp[j]<<cp[k]<<cp[m]<<cp[n]<<endl; goto end; } } } } } } cout<<"no solution"<<endl; end: free(cp); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-01 12:03:57