1020: 密码破译
1.map做法
#include <iostream>
#include <map>
#include <string.h>
using namespace std;
map<char,char> m;
char str1[]="IUJTMFHXOKBQEAPZCDWRYNVSGL";
char str2[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
for(int i=0;i<26;i++){
m[str1[i]]=str2[i];
}
int n;
cin>>n;
char code[105];
while(n--){
cin>>code;
for(unsigned int i=0;i<strlen(code);i++){
cout<<m[code[i]];
}
cout<<endl;
}
return 0;
}
2.纯字符串做法
#include <iostream>
using namespace std;
string s="IUJTMFHXOKBQEAPZCDWRYNVSGL";
string ss="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string c;
char str[1000];
int main()
{
int n;
for(int i=0;i<26;i++) str[s[i]-'A']=ss[i];
cin>>n;
getchar();
while(n--)
{
getline(cin,c);
for(int i=0;i<c.size();i++) cout<<str[c[i]-'A'];
cout<<endl;
}
return 0;
}