B. Keyboard Layouts
題目連結
分類:字元串、模拟
1.題意概述
- 給你26個字母的映射(均為小寫),再給你一串長度不大于1000的字元串,要你輸出它的映射結果。
2.解題思路
- map直接存,注意的是大寫變換以後還是大寫,還有數字不需要映射!
3.AC代碼
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100010
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
const int mod = + ;
typedef long long ll;
typedef unsigned long long ull;
map<int, int> mp;
char s1[], s2[], ch[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
scanf("%s%s", s1, s2);
for (int i = ; i < ; i++)
{
char a = s1[i], b = s2[i];
mp[a - 'a'] = b - 'a';
}
scanf("%s", ch);
int len = strlen(ch);
// printf("%s\n", ch);
for (int i = ; i < len; i++)
{
if ('0' <= ch[i] && ch[i] <= '9')
{
putchar(ch[i]);
continue;
}
char c = ch[i];
bool uppercase = ;
if (c <= 'Z')
{
uppercase = ;
c -= 'A';
}
else
c -= 'a';
int ans = mp[c];
if (uppercase)
putchar(ans + 'A');
else
putchar(ans + 'a');
}
puts("");
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}