UVa 1339 sort ent Cipher [sort], 1339 cipher
/*
Old password for Chinese questions
You can see if you can change the location of the first character to exactly match the 26 letters of the second character.
Solution: count the number of characters in two strings. If the number of characters in each string is the same, yes is output; otherwise, no is output.
Difficulties: it is a little difficult to count the number of times each character appears.
Key Point: Sorting
Problem solving person: lingnichong
Solution time:
Experience in solving problems: a good question
*/
1339-maximum ent CipherTime limit: 3.000 seconds |
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char cot1[300],cot2[300];int a[30],b[30];int main(){int i,l,len1,len2;while(~scanf("%s%s",cot1,cot2)){memset(a,0,sizeof(a));memset(b,0,sizeof(b));len1=strlen(cot1);len2=strlen(cot2);if(len1>len2) l=len1;else l=len2;for(i=0;i<l;i++){++a[cot1[i] - 'A'];++b[cot2[i] - 'A'];}sort(a,a+26);sort(b,b+26);for(i=0;i<26;i++)if(a[i] != b[i]) break;printf(i==26?"YES\n" : "NO\n");}return 0;}