英語學的差,ac都難555.比如說這題,大牛推薦的水題,興高采烈的來了,看完了,准備寫代碼時感覺到不對。果斷去評論區看了下= =坑啊這。還好沒直接碼,題目直接理解錯了有木有!同志們你們看懂了麼?→_→
Ancient Cipher
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 29640 Accepted: 9684Description
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 and permutation cipher.
Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from ‘A’ to ‘Y’ to the next ones in the alphabet, and changes ‘Z’ to ‘A’, to the message “VICTORIOUS” one gets the message “WJDUPSJPVT”.
Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation <2, 1, 5, 4, 3, 7, 6, 10, 9, 8> to the message “VICTORIOUS” one gets the message “IVOTCIRSUO”.
It was quickly noticed that being applied separately, both substitution cipher and permutation cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result was encrypted using permutation cipher. Encrypting the message “VICTORIOUS” with the combination of the ciphers described above one gets the message “JWPUDJSTVP”.
Archeologists have recently found the message engraved on a stone plate. At the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. They have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. They need a computer program to do it, so you have to write one.Input
Input contains 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 are equal and do not exceed 100.Output
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.
Sample Input
JWPUDJSTVP
VICTORIOUSSample Output
YES
這裡把討論區的帖子拿出來跟大家分享:
這道題如果沒看懂題意,絕對不是水題,能愁死你,而如果看懂了的話,的確稍微有點小水。
關鍵是對代替加密和置換加密的理解,題目中給出的例子容易誤導你進入誤區: 代替加密是按照一定規律來的。所以你會很容易的想到先排序,找兩個字符串的差距,如果一樣就YES了。。
其實,代替加密沒有“規律”!A可以對應任意的26個字母。
不知道說明白了沒有所以 是否相同的標准就是 1 兩個字符串初始長度是否相同 2. 頻率分布是否相同(不管哪個字母的頻率,只要頻率從小到大排列出來,兩個字符串完全相同就可以)
舉個例子:
abbccc
mqqbbb
YES 頻率都是 1 2 3aabbcc
mnnjjj
NO 頻率分別為 2 2 2和 1 2 3好了,大體上就這樣。
然後,是代碼。。。按部就班
#include
#include
#include
char s1[105], s2[105];
int main()
{
gets(s1);
gets(s2);
int len1 = strlen(s1);
int len2 = strlen(s2);
if (len1 != len2)
{
printf("NO\n");
return 0;
}
int a[26]={0};
int b[26]={0};
int i;
for(i=0; i