http://codeforces.com/problemset/problem/831/B
题目大意:给出两个键盘,他们布局相同,只是他们对应位置的字母不一定相同。然后给出一段字符串,由第一个键盘打出,现在要求在和第一个键盘相同的键位上用第二个键盘打出一段字符串。
解法:怎么搞都行。
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main() {
char str1[35], str2[35], tmp[1005], ans[1005];
int cnt[35];
scanf("%s", str1);
scanf("%s", str2);
scanf("%s", tmp);
for(int i = 0; str1[i]; i++) {
cnt[str1[i] - 'a'] = i;
}
for(int i = 0; tmp[i]; i++) {
if(tmp[i] >= 'a' && tmp[i] <= 'z')
ans[i] = str2[cnt[tmp[i] - 'a']];
else if(tmp[i] >= 'A' && tmp[i] <= 'Z')
ans[i] = str2[cnt[tmp[i] - 'A']] - 32;
else
ans[i] = tmp[i];
}
ans[strlen(tmp)] = '\0';
printf("%s\n", ans);
return 0;
}
本文解析了CodeForces上的一道题目,该题要求根据两个不同布局的键盘,将第一个键盘输入的字符串转换为第二个键盘对应的字符。通过构建字符映射表的方式,实现了字符串的有效转换。
1629

被折叠的 条评论
为什么被折叠?



