Ancient Cipher UVA - 1339(排序)

题目:

题目链接–VJ
题目大意:给出长度相同的两字符串,判断1串可否由每个字母进行映射得到2串(映射必须为一一映射)

Sample Input

JWPUDJSTVP
VICTORIOUS
MAMA
ROME
HAHA
HEHE
AAA
AAA
NEERCISTHEBEST
SECRETMESSAGES

Sample Output

YES
NO
YES
YES
NO

思路

既然一一映射,则无需关心字母是谁,只关心字母出现的次数,存数组排序后对比即可

AC代码
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100+10;
int main()
{
    string s1,s2;
    while(cin>>s1>>s2)
    {
        int a1[26]={0},a2[26]={0};
        for(int i=0;i<s1.length();i++)
        {
            a1[s1[i]-'A']++;
            a2[s2[i]-'A']++;
        }
        sort(a1,a1+26);
        sort(a2,a2+26);
        if(memcmp(a1,a2,sizeof(a1))==0)//mem较快
            cout << "YES" << endl;
        else
            cout << "NO"  << endl;
    }
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值