努力过

两年。

zoj 3878 Convert QWERTY to Dvorak 【模拟】

Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a broken Caps Lock key, so Edward never presses the broken Caps 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;
题意:如题,纯模拟,我看别人直接用数组,我还用map容器这么复杂,注意的是,数组范围,100千字节,而不是100字节,╭(╯^╰)╮,森气!
//第一步查找map,如果没有,转为小写字母再进行查找,此时如果没有,判断两种特殊情况,否则原样输出 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<map>
#include<iostream>
using namespace std;
const int maxn = 1100000;
char str[maxn];
map<string,int>id;

int main()
{
	int i,j;
	string s,s2;
	id["_"] = '{';
	id["-"] = '[';
	id["+"] = '}';
	id["="] = ']';
	id["Q"] = '"';
//	id["q"] = ''';
	id["W"] = '<';
	id["w"] = ',';
	id["E"] = '>';
	id["e"] = '.';
	id["R"] = 'P';
	id["T"] = 'Y';
	id["Y"] = 'F';
	id["U"] = 'G';
	id["I"] = 'C';
	id["O"] = 'R';
	id["P"] = 'L';
	id["{"] = '?';
	id["["] = '/';
	id["}"] = '+';
	id["]"] = '=';
	id["S"] = 'O';
	id["D"] = 'E';
	id["F"] = 'U';
	id["G"] = 'I';
	id["H"] = 'D';
	id["J"] = 'H';
	id["K"] = 'T';
	id["L"] = 'N';
	id[":"] = 'S';
	id[";"] = 's';
//	id["""] = '_';
	id["'"] = '-';
	id["Z"] = ':';
	id["z"] = ';';
	id["X"] = 'Q';
	id["C"] = 'J';
	id["V"] = 'K';
	id["B"] = 'X';
	id["N"] = 'B';
	id["<"] = 'W';
	id[","] = 'w';
	id[">"] = 'V';
	id["."] = 'v';
	id["?"] = 'Z';
	id["/"] = 'z';
	while(gets(str)!=NULL)
	{
		s2.clear();
		for(i = 0; str[i]!='\0'; i ++)
		{
			s.clear();
			s = str[i];
			if(id.count(s))
			{
				s2 += id[s];
			}
			else
			{
				if(str[i] == 'q')//判断特殊字符 
				
				{
					s = str[i]-74;
					s2 += s;
				}
				else if(str[i]>='a'&&str[i]<='z')//如果有小写字母 
				{
					s = str[i]-32;//转化为大写进行查找 
					if(id.count(s))//找到则按小写存入 
					{
						s = id[s]+32;
						s2 += s;
					}
					else//找不到映射则原样存入 
					{
						s = str[i];
						s2 += s;
					}
				}
				else if(str[i] == 34)//特判特殊字符 
				{
					s = '_';
					s2 += s;
				}
				else//其余情况原样存入 
				{
					s = str[i];
					s2 += s;
				}
			}
		}
		
		cout<<s2<<endl;
	 } 
	return 0;
}



阅读更多
个人分类: ACM--基础 ZOJ
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

zoj 3878 Convert QWERTY to Dvorak 【模拟】

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭