You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
map<char,char>m0,m1; //m0记录密文对明文m1记录明文对密文
char miwen[10000],mingwen[10000],target[10000];
int main()
{
gets(miwen);//输入密文
gets(mingwen);//输入明文
gets(target);//输入要翻译的信息
//第一个for循环用来记录明文和密文的对应关系
for(int i=0;i<strlen(miwen);i++)
{
//判断密文多对一或明文多对一的情况如果符合这种情况说明和规则不符直接输出Failed
if((m0.count(miwen[i]) && m0[miwen[i]]!=mingwen[i]) || (m1.count(mingwen[i]) && m1[mingwen[i]]!=miwen[i]))
{
cout<<"Failed";
return 0;
}
//如果符合规则,则记录
else
{
m0[miwen[i]]=mingwen[i];
m1[mingwen[i]]=miwen[i];
}
}
//第二个for循环用来判断是否符合第一条规则即A~Z全部有对应的密文
char temp='A';
for(int i=0;i<26;i++)
{
//判断是否A~Z都有密文如果发现没有密文的说明和规则不符直接输出Failed
if(!m1.count(temp+i))
{
cout<<"Failed";
return 0;
}
}
//如果运行到了这里说明所有规则都符合。直接第三个for循环输出结果
for(int i=0;i<strlen(target);i++)
{
if(target[i]!=' ')//注意输入的翻译信息行末有空格!!
cout<<m0[target[i]];
}
return 0;
}