本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
题目地址: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3878
思路
映射,建两个字符数组,按照相同键位顺序存储所有字符。输入字符串后,利用两层循环依次转换各个字符,最后输出转换后的字符串。
需要注意的地方
1.字符顺序要一一对应。
2.本题数据量较大。输出时应以字符串形式输出以提高效率,若以字符形式输出会超时。
Show me the code
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
char a[] = {"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"};
char b[] = {"`1234567890[]',.pyfgcrl/=\aoeuidhtns-;qjkxbmwvz~!@#$%^&*(){}\"<>PYFGCRL?+|AOEUIDHTNS_:QJKXBMWVZ"};
char ch[1000005];
int main()
{
while(gets(ch))
{
int len = strlen(ch), len1 = strlen(a);
for(int i = 0;i < len;i++)
{
for(int j = 0;j < len1;j++)
{
if(ch[i] == a[j]){
ch[i] = b[j];
break;
}
}
}
puts(ch);
}
}