Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8371 | Accepted: 4007 |
Description
Input
Output
Sample Input
O S, GOMR YPFSU/
Sample Output
I AM FINE TODAY.
算法分析:下面的算法,写起来实在是过于麻烦而且容易出错,现提供常量数组的做法。初始化定义一个字符数组s[]={",,,,,,,,,,,,"} 将全部的键盘输进去,输出时,先遍历一遍找到对应的字符,然后输出该字符的钱一个字符就可以了,此写法不容易出错!
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char s[1000000]; int main() { char t[10000]; int i, j; int len; //定义区 s['1']='~'; s['2']='1'; s['3']='2'; s['4']='3'; s['5']='4'; s['6']='5'; s['7']='6'; s['8']='7'; s['9']='8'; s['0']='9'; s['-']='0'; s['=']='-'; s['W']='Q'; s['E']='W'; s['R']='E'; s['T']='R'; s['Y']='T'; s['U']='Y'; s['I']='U'; s['O']='I'; s['P']='O'; s['[']='P'; s[']']='['; s['\\']=']'; s['\'']=';'; s['S']='A'; s['D']='S'; s['F']='D'; s['G']='F'; s['H']='G'; s['J']='H'; s['K']='J'; s['L']='K'; s[';']='L'; s['X']='Z'; s['C']='X'; s['V']='C'; s['B']='V'; s['N']='B'; s['M']='N'; s[',']='M'; s['.']=','; s['/']='.'; while(gets(t)!=NULL) { len = strlen(t); for(i=0; i<len; i++) { if(t[i]==' ') { printf(" "); } else { printf("%c", s[t[i]] ); } } printf("\n"); } return 0; }