POJ 之 WERTYU

WERTYU
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8371   Accepted: 4007

Description

POJ 之 WERTYU
A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.

Input

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input.

Output

You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the 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;

}

 

你可能感兴趣的:(poj)