UVa 1339 Ancient Cipher

  统计每个字母出现的次数,然后进行比较就行了。代码如下:

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8 #ifdef LOCAL
 9     freopen("in", "r", stdin);
10 #endif
11     char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
12     char s[110];
13     while(scanf("%s", s) != EOF)
14     {
15         int len = strlen(s);
16         int a[26];
17         memset(a, 0, sizeof(a));
18         for(int i = 0; i < len; i++)
19             a[strchr(alpha, s[i])-alpha]++;
20         scanf("%s", s);
21         int b[26];
22         memset(b, 0, sizeof(b));
23         for(int i = 0; i < len; i++)
24             b[strchr(alpha, s[i])-alpha]++;
25         sort(a, a+26);
26         sort(b, b+26);
27         int i;
28         for(i = 0; i < 26; i++)
29             if(a[i] != b[i])   break;
30         if(i == 26)   printf("YES\n");
31         else printf("NO\n");
32     }
33     return 0;
34 }
35         
原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3001086.html