【codevs 4716】破损的键盘2

来源:互联网 发布:数据库题库 编辑:程序博客网 时间:2024/04/28 05:00

4716 破损的键盘2
时间限制: 1 s
空间限制: 16000 KB
题目等级 : 白银 Silver
题解
查看运行结果
题目描述 Description
这个键盘坏掉了。字母的顺序被弄乱了。

你毫不知情,当你打印文档的时候,你甚至没有打开显示屏。

当你打开显示屏的时候,你看到了一个悲剧的文档。

你的任务,就是将这一份悲剧的文档还原成正常的文档。

题目中,所有的字母都向右移了一格,如N–>M,(注意大小写)

在最右边的字母会转换成最左边的字母,如m–>z (注意大小写)

输入描述 Input Description
输入是一个由字母和下划线(下划线没有变化)组成的字符串

输出描述 Output Description
输出是还原后的文档。

样例输入 Sample Input
样例:

Jraap_Eptaf

样例输出 Sample Output
样例:

Hello_World

数据范围及提示 Data Size & Hint
字符长度<=100000;

1.模拟

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100005;char s[MAXN];int lens;//键盘什么样就怎么返回char change(char x,int in){    if(in == 0)// xiaoxie    {        if(x == 'q')        return 'p';        if(x == 'w')        return 'q';         if(x == 'e')        return 'w';        if(x == 'r')        return 'e';        if(x == 't')        return 'r';        if(x == 'y')        return 't';        if(x == 'u')        return 'y';        if(x == 'i')        return 'u';        if(x == 'o')        return 'i';        if(x == 'p')        return 'o';        if(x == 'a')        return 'l';        if(x == 's')        return 'a';        if(x == 'd')        return 's';        if(x == 'f')        return 'd';        if(x == 'g')        return 'f';        if(x == 'h')        return 'g';        if(x == 'j')        return 'h';        if(x == 'k')        return 'j';        if(x == 'l')        return 'k';        if(x == 'z')        return 'm';        if(x == 'x')        return 'z';        if(x == 'c')        return 'x';        if(x == 'v')        return 'c';        if(x == 'b')        return 'v';        if(x == 'n')        return 'b';        if(x == 'm')        return 'n';    }    else if(in == 1)// daxie    {        if(x == 'Q')        return 'P';        if(x == 'W')        return 'Q';         if(x == 'E')        return 'W';        if(x == 'R')        return 'E';        if(x == 'T')        return 'R';        if(x == 'Y')        return 'T';        if(x == 'U')        return 'Y';        if(x == 'I')        return 'U';        if(x == 'O')        return 'I';        if(x == 'P')        return 'O';        if(x == 'A')        return 'L';        if(x == 'S')        return 'A';        if(x == 'D')        return 'S';        if(x == 'F')        return 'D';        if(x == 'G')        return 'F';        if(x == 'H')        return 'G';        if(x == 'J')        return 'H';        if(x == 'K')        return 'J';        if(x == 'L')        return 'K';        if(x == 'Z')        return 'M';        if(x == 'X')        return 'Z';        if(x == 'C')        return 'X';        if(x == 'V')        return 'C';        if(x == 'B')        return 'V';        if(x == 'N')        return 'B';        if(x == 'M')        return 'N';    }    else    return x;}char out(char x){    if('a' <= x && x <= 'z')        return change(x,0);    else if('A' <= x && x <= 'Z')        return change(x,1);    else    return change(x,2);}int main(){    cin >> s;    lens = strlen(s);    for(int i = 0; i < lens; i ++)        cout << out(s[i]);    return 0;}

2.转化
//ASCII码

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100005;int lens;char s[MAXN];int num[26] = {12,22,24,19,23,4,6,7,21,8,10,11,14,2,9,15,16,5,1,18,25,3,17,26,20,13};int main(){    scanf("%s",s + 1);    lens = strlen(s + 1);    for(int i = 1;i <= lens; i ++)    {        if(s[i] == '_') printf("_");        else if(s[i] - 'a' >= 0 && s[i] - 'a' <= 26)        printf("%c",('a' + num[s[i] - 'a'] - 1));        else  printf("%c",('A' + num[s[i] - 'A'] - 1));    }    return 0;}
1 0
原创粉丝点击