CodeFroces 831B. Keyboard Layouts(构造题)

来源:互联网 发布:淘宝网店实战宝典txt 编辑:程序博客网 时间:2024/06/17 05:40

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;elseans[i] = tmp[i];}ans[strlen(tmp)] = '\0';printf("%s\n", ans);return 0;}