Codeforces

来源:互联网 发布:浙江省纺织品出口数据 编辑:程序博客网 时间:2024/06/12 00:08

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 = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;map<int, int> mp;char s1[28], s2[28], 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 = 0; i < 26; 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 = 0; i < len; i++)    {        if ('0' <= ch[i] && ch[i] <= '9')        {            putchar(ch[i]);            continue;        }        char c = ch[i];        bool uppercase = 0;        if (c <= 'Z')        {            uppercase = 1;            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 0;}