L_Y_T 之懒 , 天下皆知
因为发现普及试炼场的字符串板块还没有做,于是就来做做看看,结果一看是一道模拟题,于是果断选择不做,但最后看了一下其他的题目最终还是来做了
由于偷懒,L_Y_T 决定使用STL中的神奇 map , 感觉这道题应该不会TLE吧
下面是code
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std ;
map<char,char>data , vis;//data用来记录密文对应,vis是统计密文出现次数的
string s1 , s2 , s3;
int ch[27] ;//用来统计字母出现了多少个
int main () {
cin >> s1 >> s2 ;
for(int i = 0 ; i < s1.size() ; i ++) {
ch[s1[i]-'A'+1] = 1 ;
}int flag = 0 ;
for(int i = 1 ; i < 26 ; i ++) {
if(!ch[i]) flag = 1 ;
}
if(flag) {cout << "Failed\n" ; return 0 ;}//如果不足26,就是错的
for(int i = 0 ; i < s1.size() ; i ++) {
if(!data[s1[i]])
data[s1[i]] = s2[i] , vis[s2[i]] ++ ;
else if(data[s1[i]] != s2[i]) {//多对一,错
cout << "Failed\n" ;
return 0 ;
}
if(vis[s2[i]] > 1) {//一对多,错
cout << "Failed\n" ;
return 0 ;
}
}
cin >> s3 ;
string op = "" ;
for(int i = 0 ; i < s3.size() ; i ++) {
if(!data[s3[i]]) {//不全,错
cout << "Failed\n";
return 0 ;
}
op += data[s3[i]] ;
}
cout << op <<endl ;输出
return 0 ;
}