LA 3213 Ancient Cipher , NEERC 2004

【题意】给定两个长度为n的字符串,判断他们之间的26个字母是否能一一对应!(只有大写字母)

【解题思路】贪心!

【AC代码】

//cpp try two pointers

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
char s1[maxn],s2[maxn];
int a[26],b[26];
int main()
{
    while(~scanf("%s",s1)){
        scanf("%s",s2);
        int n = strlen(s1);
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0; i<n; i++){
            a[s1[i]-'A']++;
            b[s2[i]-'A']++;
        }
        sort(a,a+26);
        sort(b,b+26);
        bool fuck = true;
        for(int i=0; i<26; i++){
            if(a[i]!=b[i]){
                fuck = false;
                break;
            }
        }
        if(fuck) puts("YES");
        else puts("NO");
    }
    return 0;
}


你可能感兴趣的:(LA 3213 Ancient Cipher , NEERC 2004)