这题的话,我们依旧可以看到它里面是有空格的,所以直接用getchar函数,不断地读入字符,然后用putchar函数输出。
我们用for循环在字符串常量里面查找,如果在没到尾部且能找到的话,我们退出循环,然后输出对应的字母,如果找不到那就直接输出对应的字母,比如空格。
#include <cstdio>
int main()
{
char s[]={"`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"};
char ch;
int i;
while ((ch=getchar())!=EOF) {
/*if (ch==' ') {
printf(" ");
continue;
}
else if (ch=='
')
printf("
");
*/
for (i=0;s[i]&&s[i]!=ch;i++);
if (s[i]) {
putchar(s[i-1]);
}
else putchar(ch);
}
}