模拟 ZOJ 3878 Convert QWERTY to Dvorak

 

题目传送门

 1 /*  2  模拟:手敲map一一映射,累!  3  除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:)  4 */  5 #include <cstdio>  6 #include <iostream>  7 #include <algorithm>  8 #include <cmath>  9 #include <cstring> 10 #include <string> 11 #include <map> 12 #include <set> 13 #include <queue> 14 #include <vector> 15 using namespace std; 16 17 const int MAXN = 1e2 + 10; 18 const int INF = 0x3f3f3f3f; 19 map<char, char> m; 20 string s; 21 22 void solve(void) 23 { 24 m['~'] = '~'; m['`'] = '`'; 25 m['!'] = '!'; m['1'] = '1'; 26 m['@'] = '@'; m['2'] = '2'; 27 m['#'] = '#'; m['3'] = '3'; 28 m['$'] = '$'; m['4'] = '4'; 29 m['%'] = '%'; m['5'] = '5'; 30 m['^'] = '^'; m['6'] = '6'; 31 m['&'] = '&'; m['7'] = '7'; 32 m['*'] = '*'; m['8'] = '8'; 33 m['('] = '('; m['9'] = '9'; 34 m[')'] = ')'; m['0'] = '0'; 35 m['_'] = '{'; m['-'] = '['; 36 m['+'] = '}'; m['='] = ']'; 37 m['Q'] = '"'; m['q'] = '\''; 38 m['W'] = '<'; m['w'] = ','; 39 m['E'] = '>'; m['e'] = '.'; 40 m['R'] = 'P'; m['r'] = 'p'; 41 m['T'] = 'Y'; m['t'] = 'y'; 42 m['Y'] = 'F'; m['y'] = 'f'; 43 m['U'] = 'G'; m['u'] = 'g'; 44 m['I'] = 'C'; m['i'] = 'c'; 45 m['O'] = 'R'; m['o'] = 'r'; 46 m['P'] = 'L'; m['p'] = 'l'; 47 m['{'] = '?'; m['['] = '/'; 48 m['}'] = '+'; m[']'] = '='; 49 m['|'] = '|'; m['\\'] = '\\'; 50 m['A'] = 'A'; m['a'] = 'a'; 51 m['S'] = 'O'; m['s'] = 'o'; 52 m['D'] = 'E'; m['d'] = 'e'; 53 m['F'] = 'U'; m['f'] = 'u'; 54 m['G'] = 'I'; m['g'] = 'i'; 55 m['H'] = 'D'; m['h'] = 'd'; 56 m['J'] = 'H'; m['j'] = 'h'; 57 m['K'] = 'T'; m['k'] = 't'; 58 m['L'] = 'N'; m['l'] = 'n'; 59 m[':'] = 'S'; m[';'] = 's'; 60 m['"'] = '_'; m['\''] = '-'; 61 m['Z'] = ':'; m['z'] = ';'; 62 m['X'] = 'Q'; m['x'] = 'q'; 63 m['C'] = 'J'; m['c'] = 'j'; 64 m['V'] = 'K'; m['v'] = 'k'; 65 m['B'] = 'X'; m['b'] = 'x'; 66 m['N'] = 'B'; m['n'] = 'b'; 67 m['M'] = 'M'; m['m'] = 'm'; 68 m['<'] = 'W'; m[','] = 'w'; 69 m['>'] = 'V'; m['.'] = 'v'; 70 m['?'] = 'Z'; m['/'] = 'z'; 71 m[' '] = ' '; 72 } 73 74 int main(void) //ZOJ 3878 Convert QWERTY to Dvorak 75 { 76 //freopen ("J.in", "r", stdin); 77 78  solve (); 79 while (getline (cin, s)) 80  { 81 for (int i=0; s[i]; ++i) 82 cout << m[s[i]]; 83 cout << endl; 84  } 85 86 return 0; 87 } 88 89 /* 90 Hi, I'm Abel, a Dvorak Layout user. 91 But I've only a Qwerty keyboard. 92 The following lines are for testing: 93 1234567890 94 `~!@#$%^&*()+_-={}[]:"'<>,.?/\| 95 ABCDEFuvwxyz 96 AXJE>Ugk,qf; 97 */
 1 #include <iostream>

 2 #include <stdio.h>

 3 #include <string.h>

 4 #include <stack>

 5 #include <queue>

 6 #include <map>

 7 #include <set>

 8 #include <vector>

 9 #include <math.h>

10 #include <algorithm>

11 using namespace std; 12 #define ls 2*i

13 #define rs 2*i+1

14 #define up(i,x,y) for(i=x;i<=y;i++)

15 #define down(i,x,y) for(i=x;i>=y;i--)

16 #define mem(a,x) memset(a,x,sizeof(a))

17 #define w(a) while(a)

18 #define LL long long

19 const double pi = acos(-1.0); 20 #define Len 20005

21 #define mod 19999997

22 const int INF = 0x3f3f3f3f; 23 

24 char s1[]= {"-=_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?"}; 25 char s2[]= {"[]{}',.pyfgcrl/=\"<>PYFGCRL?+aoeuidhtns-AOEUIDHTNS_;qjkxbmwvz:QJKXBMWVZ"}; 26 char c; 27 

28 char print(char c) 29 { 30     for(int i=0; s1[i]; i++) 31         if(s1[i]==c) 32             return s2[i]; 33     return c; 34 } 35 int main() 36 { 37     w(~scanf("%c",&c)) 38     printf("%c",print(c)); 39 

40     return 0; 41 }
网上题解,两行,给跪了!

 

你可能感兴趣的:(convert)