Convert QWERTY to Dvorak (字符串)

ZOJ Problem Set - 3878
Convert QWERTY to Dvorak

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a brokenCaps Lock key, so Edward never presses the brokenCaps Lock key. Luckily, all the other keys on the QWERTY keyboard work well. Every day, he has a lot of documents to type. Thus he needs a converter to translate QWERTY into Dvorak. Can you help him?

The QWERTY Layout and the Dvorak Layout are in the following:

Qwerty Layout
The QWERTY Layout

Dvorak Layout
The Dvorak Layout

Input

A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.

Output

The Dvorak document.

Sample Input
Jgw Gqm Andpw a H.soav Patsfk f;doe
Nfk Gq.d slpt a X,dokt vdtnsaohe
Kjd yspps,glu pgld; aod yso kd;kgluZ
1234567890
`~!@#$%^&*()}"']_+-=ZQqWEwe{[\|
ANIHDYf.,bt/
ABCDEFuvwxyz
Sample Output
Hi, I'm Abel, a Dvorak Layout user.
But I've only a Qwerty keyboard.
The following lines are for testing:
1234567890
`~!@#$%^&*()+_-={}[]:"'<>,.?/\|
ABCDEFuvwxyz
AXJE>Ugk,qf;
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[1100000];//这块很坑(WA了一下午),题中说的时100 “kibibytes”,没看清,只开到110,一直错
int main()
{
	char c;
	while(gets(a)!=NULL)
	{
		int l=strlen(a);
		for(int i=0;i<l;i++)
		{
			if(a[i]=='Q')a[i]='\"';
			else if(a[i]=='q')a[i]=39;
			else if(a[i]=='W')a[i]='<';
			else if(a[i]=='w')a[i]=',';
			else if(a[i]=='E')a[i]='>';
			else if(a[i]=='e')a[i]='.';
			else if(a[i]=='R')a[i]='P';
			else if(a[i]=='r')a[i]='p';
			else if(a[i]=='T')a[i]='Y';
			else if(a[i]=='t')a[i]='y';
			else if(a[i]=='Y')a[i]='F';
			else if(a[i]=='y')a[i]='f';
			else if(a[i]=='U')a[i]='G';
			else if(a[i]=='u')a[i]='g';
			else if(a[i]=='I')a[i]='C';
			else if(a[i]=='i')a[i]='c';
			else if(a[i]=='O')a[i]='R';
			else if(a[i]=='o')a[i]='r';
			else if(a[i]=='P')a[i]='L';
			else if(a[i]=='p')a[i]='l';
			else if(a[i]=='{')a[i]='?';
			else if(a[i]=='[')a[i]='/';
			else if(a[i]=='}')a[i]='+';
			else if(a[i]==']')a[i]='=';
			else if(a[i]=='A')a[i]='A';
			else if(a[i]=='a')a[i]='a';
			else if(a[i]=='S')a[i]='O';
			else if(a[i]=='s')a[i]='o';
			else if(a[i]=='D')a[i]='E';
			else if(a[i]=='d')a[i]='e';
			else if(a[i]=='F')a[i]='U';
			else if(a[i]=='f')a[i]='u';
			else if(a[i]=='G')a[i]='I';
			else if(a[i]=='g')a[i]='i';
			else if(a[i]=='H')a[i]='D';
			else if(a[i]=='h')a[i]='d';
			else if(a[i]=='J')a[i]='H';
			else if(a[i]=='j')a[i]='h';
			else if(a[i]=='K')a[i]='T';
			else if(a[i]=='k')a[i]='t';
			else if(a[i]=='L')a[i]='N';
			else if(a[i]=='l')a[i]='n';
			else if(a[i]==':')a[i]='S';
			else if(a[i]==';')a[i]='s';
			else if(a[i]=='\"')a[i]='_';
			else if(a[i]==39)a[i]='-';	
			else if(a[i]=='Z')a[i]=':';
			else if(a[i]=='z')a[i]=';';
			else if(a[i]=='X')a[i]='Q';
			else if(a[i]=='x')a[i]='q';
			else if(a[i]=='C')a[i]='J';
			else if(a[i]=='c')a[i]='j';
			else if(a[i]=='V')a[i]='K';
			else if(a[i]=='v')a[i]='k';
			else if(a[i]=='B')a[i]='X';
			else if(a[i]=='b')a[i]='x';
			else if(a[i]=='N')a[i]='B';
			else if(a[i]=='n')a[i]='b';
			else if(a[i]=='M')a[i]='M';
			else if(a[i]=='m')a[i]='m';
			else if(a[i]=='<')a[i]='W';
			else if(a[i]==',')a[i]='w';
			else if(a[i]=='>')a[i]='V';
			else if(a[i]=='.')a[i]='v';
			else if(a[i]=='?')a[i]='Z';
			else if(a[i]=='/')a[i]='z';
			else if(a[i]=='_')a[i]='{';
			else if(a[i]=='-')a[i]='[';
			else if(a[i]=='+')a[i]='}';
			else if(a[i]=='=')a[i]=']';
		}
		for(int i=0;i<l;i++)
			printf("%c",a[i]);
			printf("\n");
	}
	return 0;
} 
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char a[]={"QqWwEeRrTtYyUuIiOoPp{[}]AaSsDdFfGgHhJjKkLl:;\"'ZzXxCcVvBbNnMm<,>.?/_-+="};
char b[]={"\"'<,>.PpYyFfGgCcRrLl?/+=AaOoEeUuIiDdHhTtNnSs_-:;QqJjKkXxBbMmWwVvZz{[}]"}; 
char c;
char print(char c)
{
    for(int i=0;a[i];i++)
        if(a[i]==c)
            return b[i];
    return c;
}
int main()
{
    while(scanf("%c",&c)!=EOF)
    	printf("%c",print(c));
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值