【ZOJ】[3878]Convert QWERTY to Dvorak

Problem Description

Loading...

Problem Analysis

Pretty interesting
but while writing it I felt this problem was quite brutal

The idea is to build two char arrays holding the corresponding keymaps
so for each character we only need to find its position in one table
and its counterpart is the character at the same position in the other table

Note that for quotes like the double quote and single quote you must remember to use escape characters when storing them
and also count the positions carefully while writing
don’t GG on these small details

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
#include<string.h>
char s1[100]= {"_+-=QWEqweRTYUIOPrtyuiop{}[]SDFGHJKLsdfghjkl:\";\'ZXCVBNzxcvbn<>?,./"};
char s2[100]= {"{}[]\"<>\',.PYFGCRLpyfgcrl?+/=OEUIDHTNoeuidhtnS_s-:QJKXB;qjkxbWVZwvz"};
int find(char c) {
	int i=0;
	while(c!=s1[i])
		i++;
	return i;
}
char s[1000000];
int main() {
	while(gets(s)!=NULL) {
		int l=strlen(s);
		for(int i=0; i<l; i++) {
			if(find(s[i])>65)
				printf("%c",s[i]);
			else
				printf("%c",s2[find(s[i])]);
		}
		printf("\n");
	}
	return 0;
}

Problem link: 【ZOJ】[3878]Convert QWERTY to Dvorak

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...