简单暴力的一道题,以前做过,现在就不浪费时间自己打表了。。。
粘上一种稍微聪明的方法和一种最笨的方法。。。
聪明一些的方法:
#include <cstdio> #include <cstring> const char dic[]=" 1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; char str[1000]; int main() { int i,j,l,l2=strlen(dic); while (gets(str)!=NULL) { l=strlen(str); for (i=0;i<l;i++) { for (j=1;str[i]!=dic[j] && j<l2;j++); if (j<l2) printf("%c",dic[j-1]); else printf(" "); } printf("\n"); } }
最笨的方法:
#include"stdio.h" #include"string.h" int main() { char s[100]; char a[100]; s[';'] = 'L'; s['L'] = 'K'; s['K'] = 'J'; s['J'] = 'H'; s['H'] = 'G'; s['G'] = 'F'; s['F'] = 'D'; s['D'] = 'S'; s['S'] = 'A'; s[','] = 'M'; s['M'] = 'N'; s['N'] = 'B'; s['B'] = 'V'; s['V'] = 'C'; s['C'] = 'X'; s['X'] = 'Z'; s['['] = 'P'; s['P'] = 'O'; s['O'] = 'I'; s['I'] = 'U'; s['U'] = 'Y'; s['Y'] = 'T'; s['T'] = 'R'; s['R'] = 'E'; s['E'] = 'W'; s['W'] = 'Q'; s['/'] = '.'; s['\''] = ';'; s[']'] = '['; s['\\'] = ']'; s['.'] = ','; s['='] = '-'; s['-'] = '0'; s['0'] = '9'; s['9'] = '8'; s['8'] = '7'; s['7'] = '6'; s['6'] = '5'; s['5'] = '4'; s['4'] = '3'; s['3'] = '2'; s['2'] = '1'; s['1'] = '`'; s[' ']=' '; while(gets(a)) { int i; for(i=0;i<strlen(a);i++) printf("%c",s[a[i]]); printf("\n"); } return 0; }