ZOJ3878: Convert QWERTY to Dvorak(浙江省赛2015)

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.

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

<h4< dd="">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 <ctype.h>
#define N 100005
char c[N];

int main()
{
    int n, i, j, k, T;
    char a[]= {"_+-=wertyuiop[]\asdfghjkl;zxcvbnm,./WERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>?"};
    char b[]= {"{}[],.pyfgcrl/=\aoeuidhtns;qjkxbmwvz<>PYFGCRL?+|AOEUIDHTNS:QJKXBMWVZ"};
    while(gets(c))
    {
        for(i=0; i<strlen(c); i++)
        {
            k=0;
            if(c[i]==39)
            {
                printf("%c", 45);
                k=1;
            }
            else if(c[i]==34)
            {
                k=1;
                printf("%c", 95);
            }
            else if(c[i]=='q')
            {
                k=1;
                printf("%c", 39);
            }
            else if(c[i]=='Q')
            {
                k=1;
                printf("%c", 34);
            }
            for(j=0; j<strlen(a); j++)
            {
                if(c[i]==a[j])
                {
                    printf("%c", b[j]);
                    k=1;
                    break;
                }
            }
            if(k==0)
            {
                printf("%c", c[i]);
            }
        }
        printf("\n");
    }
    return 0;
}

 

posted on 2017-05-02 17:54  小春天  阅读(208)  评论(0编辑  收藏  举报

导航