POJ 之 WERTYU

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

Description


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;
}

 

转载于:https://www.cnblogs.com/yspworld/p/3979979.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值