poj2159

Ancient Cipher #include “iostream” #include “math.h” using namespace std; int compare(int *str1,int *str2); int main(int argc, _TCHAR* argv[]) { char old[101]; int s1[26]; int s2[26]; for(int j=0;j<26;j++) { s1[j]=0; s2[j]=0; } cin>>old; int i=0; while(old[i]!=0) { s1[old[i]-‘A’]++; i++; } cin>>old; i=0; while(old[i]!=0) { s2[old[i]-‘A’]++; i++; } if(compare(s1,s2)==1) cout<<“YES”<<endl; else cout<<“NO”<<endl; return 0; } int compare(int *str1,int *str2) { int i=0; while(i<26) { int j=0; while(j<26) { if(str1[i]==str2[j]) { str2[j]=’101′; break; } else j++; } if(j==26)return 0; i++; } return 1; }

点赞