您的位置:首页 > 其它

UVA - 1339 Ancient Cipher

2015-06-23 13:41 387 查看
//

1.数组没初始化调了一下 还是直接输出数组

2.排序的时候元素没注意是26.

//

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 100 + 5;
int main()
{
    char str1[maxn], str2[maxn];
    while(cin >> str1 >> str2)
    {
        int len1 = strlen(str1);
        int len2 = strlen(str2);

        int cnt1[maxn], cnt2[maxn];

        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));

        for(int i = 0; i < len1; ++i) cnt1[str1[i] - 'A']++;
        for(int i = 0; i < len2; ++i) cnt2[str2[i] - 'A']++;

        sort(cnt1, cnt1+26);
        sort(cnt2, cnt2+26);

        bool ok = true;
        for(int i = 0; i < 26; ++i)
        {
            if(cnt1[i] != cnt2[i])
            {
                ok = false; break;
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: