#include <stdio.h>
#include <iostream>
#include<math.h>
using namespace std;
char *s ="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
int main()
{
int i,c;
while((c=getchar())!=EOF)
{
for(i=1;s[i]&&s[i]!=c;i++);
if(s[i])
putchar(s[i-1]);
else putchar(c);
}
return 0;
system("pause");
}
代码简化后:
#include <stdio.h>
#include <iostream>
using namespace std;
char s [] ="`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./";
int main()
{
int i;
char c;
while(scanf("%c",&c)==1)
{
for(i=1;s[i]!=c;i++);
s[i]==c?printf("%c",s[i-1]):printf("%c",s[i]);
}
return 0;
system("pause");
}