UVA 1339 Ancient Cipher古老的密碼【NEERC 2004】【劉汝佳紫書4-1】
阿新 • • 發佈:2018-12-26
Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher
Input
Input file contains several test cases. Each of them consists of two lines. The first line contains the message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters of the English alphabet. The second line contains the original message that is conjectured to be encrypted in the message on the first line. It also contains only capital letters of the English alphabet. The lengths of both lines of the input file are equal and do not exceed 100. For each test case, print one output line. Output `YES' if the message on the first line of the input file could be the result of encrypting the message on the second line, or `NO' in the other case.JWPUDJSTVP VICTORIOUS MAMA ROME HAHA HEHE AAA AAA NEERCISTHEBEST SECRETMESSAGES
YES NO YES YES NO
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const char map[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main (void)
{
int cnt[30],cnt2[30],flag;
char a[105],b[105];
while(~scanf("%s%s",a,b))
{
flag=0;
memset(cnt,0,sizeof(cnt));
memset(cnt2,0,sizeof(cnt2));//sizeof(cnt2)之前打成cnt WA 注意細節 不要複製程式碼
for(int i=0; i<strlen(a); i++)
{
for(int ii=0; ii<strlen(map); ii++)
{
if(map[ii]==a[i])
{
cnt[ii]++;
}
}
}
for(int i=0; i<strlen(b); i++)
{
for(int ii=0; ii<strlen(map); ii++)
{
if(map[ii]==b[i])
{
cnt2[ii]++;
}
}
}
sort(cnt,cnt+26,greater<int>());//greater<int >() 從大到小 int型的排序 如果是less 是從小到大
sort(cnt2,cnt2+26,greater<int>());
for(int i=0; i<26; i++)
{
if(cnt[i]!=cnt2[i])
{
flag=1;
break;
}
}
if(flag)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}