可惜没如果=_=
时光的河入海流

 

 个人第一想法是对于每一个输入的字符都用if进行处理,很显然操作巨复杂

所以选择开一个常量数组对于每一个读入的字符,直接输出它的前一个就行了

对于这种有一一对应关系的问题,可以考虑用常量数组解决。

此题一定注意除了键盘上可见的一些字符,还有空格tab等

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 char c,s[]=" `1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
 4 int ls;
 5 int main(){
 6     freopen ("wertyu.in","r",stdin);
 7     freopen ("wertyu.out","w",stdout);
 8     int i,j;
 9     ls=strlen(s+1);
10     while (c=getchar(),c!=EOF){
11         for (i=1;i<=ls && s[i]!=c;i++);
12         if (i<=ls) 
13             putchar(s[i-1]);
14         else
15             putchar(c);
16     }
17     return 0;
18 }

 

posted on 2020-10-17 23:40  珍珠鸟  阅读(176)  评论(0)    收藏  举报