标签:
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:
![]() |
| The QWERTY Layout |
|---|
|
|
![]() |
| The Dvorak Layout |
|---|
|
|
A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.
The Dvorak document.
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
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;
这题写了半天。。思路很简单,就是比较麻烦。但是当时交了4次!!都是段错误好像。然后我把gets换了,然后写了getline(cin,s)竟然ac了。。
但是晚上学长给我们发了题解,写的好简单http://blog.csdn.net/libin56842/article/details/45272869
我们的代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string a;
int i,len;
while(getline(cin,a))
{
len=a.size();
for(i=0;i<len;i++)
{
if(a[i]=='Q')
{
a[i]='"';
cout<<a[i];}
else if(a[i]=='q')
cout<<"'";
else if(a[i]=='W')
cout<<"<";
else if(a[i]=='w')
cout<<",";
else if(a[i]=='E')
cout<<">";
else if(a[i]=='e')
cout<<".";
else if(a[i]=='R')
cout<<"P";
else if(a[i]=='r')
cout<<"p";
else if(a[i]=='T')
cout<<"Y";
else if(a[i]=='t')
cout<<"y";
else if(a[i]=='Y')
cout<<"F";
else if(a[i]=='y')
cout<<"f";
else if(a[i]=='U')
cout<<"G";
else if(a[i]=='u')
cout<<"g";
else if(a[i]=='I')
cout<<"C";
else if(a[i]=='i')
cout<<"c";
else if(a[i]=='O')
cout<<"R";
else if(a[i]=='o')
cout<<"r";
else if(a[i]=='P')
cout<<"L";
else if(a[i]=='p')
cout<<"l";
else if(a[i]=='_')
cout<<"{";
else if(a[i]=='-')
cout<<"[";
else if(a[i]=='+')
cout<<"}";
else if(a[i]=='=')
cout<<"]";
else if(a[i]=='{')
cout<<"?";
else if(a[i]=='[')
cout<<"/";
else if(a[i]=='}')
cout<<"+";
else if(a[i]==']')
cout<<"=";
else if(a[i]=='S')
cout<<"O";
else if(a[i]=='s')
cout<<"o";
else if(a[i]=='D')
cout<<"E";
else if(a[i]=='d')
cout<<"e";
else if(a[i]=='F')
cout<<"U";
else if(a[i]=='f')
cout<<"u";
else if(a[i]=='G')
cout<<"I";
else if(a[i]=='g')
cout<<"i";
else if(a[i]=='H')
cout<<"D";
else if(a[i]=='h')
cout<<"d";
else if(a[i]=='J')
cout<<"H";
else if(a[i]=='j')
cout<<"h";
else if(a[i]=='K')
cout<<"T";
else if(a[i]=='k')
cout<<"t";
else if(a[i]=='L')
cout<<"N";
else if(a[i]=='l')
cout<<"n";
else if(a[i]==':')
cout<<"S";
else if(a[i]==';')
cout<<"s";
else if(a[i]=='"')
cout<<"_";
else if(a[i]=='\'')
cout<<"-";
else if(a[i]=='Z')
cout<<":";
else if(a[i]=='z')
cout<<";";
else if(a[i]=='X')
cout<<"Q";
else if(a[i]=='x')
cout<<"q";
else if(a[i]=='C')
cout<<"J";
else if(a[i]=='c')
cout<<"j";
else if(a[i]=='V')
cout<<"K";
else if(a[i]=='v')
cout<<"k";
else if(a[i]=='B')
cout<<"X";
else if(a[i]=='b')
cout<<"x";
else if(a[i]=='N')
cout<<"B";
else if(a[i]=='n')
cout<<"b";
else if(a[i]=='<')
cout<<"W";
else if(a[i]==',')
cout<<"w";
else if(a[i]=='>')
cout<<"V";
else if(a[i]=='.')
cout<<"v";
else if(a[i]=='?')
cout<<"Z";
else if(a[i]=='/')
cout<<"z";
else
cout<<a[i];
}
cout<<endl;
}
return 0;
}//大牛的代码:
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <algorithm> using namespace std; #define ls 2*i #define rs 2*i+1 #define up(i,x,y) for(i=x;i<=y;i++) #define down(i,x,y) for(i=x;i>=y;i--) #define mem(a,x) memset(a,x,sizeof(a)) #define w(a) while(a) #define LL long long const double pi = acos(-1.0); #define Len 20005 #define mod 19999997 const int INF = 0x3f3f3f3f; char s1[]= {"-=_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"}; char s2[]= {"[]{}',.pyfgcrl/=\"<>PYFGCRL?+aoeuidhtns-AOEUIDHTNS_;qjkxbmwvz:QJKXBMWVZ"}; char c; char print(char c) { for(int i=0; s1[i]; i++) if(s1[i]==c) return s2[i]; return c; } int main() { w(~scanf("%c",&c)) printf("%c",print(c)); return 0; }
标签:
原文地址:http://blog.csdn.net/zuguodexiaoguoabc/article/details/45274035