24h購物| | PChome| 登入
2013-02-14 17:21:47| 人氣2,015| 回應0 | 上一篇 | 下一篇

[UVA][字串處理] 11278 - One-Handed Typist

推薦 0 收藏 0 轉貼0 訂閱站台

Problem A

ONE-HANDED TYPIST

Recently, a programming contest coach had a terrible accident and broke his left arm. It was then that he discovered how dificult it was to type with only one hand. He really needed to find a way to increase his typing speed, since he had to create problems in a hurry for an upcoming programming contest.

His solution was to switch from the standard QWERTY keyboard layout to a right-handed Dvorak keyboard layout (see diagrams below). It is pretty easy on a modern machine to change the keyboard layout in software, so that striking a key on the standard keyboard would give you the character at that position on the desired layout, whether or not it matches the physically labeled character.

The standard QWERTY keyboard layout, shift-modified on right.

The right-handed Dvorak keyboard layout, shift-modified on right.

One day, as the coach was typing out a problem statement with his right hand, he discovered that he had forgotten to change the keyboard layout from QWERTY to Dvorak on the machine! Naturally, all the text came out scrambled, because he had struck the keys as if it were a right-handed Dvorak keyboard. Alas, it would take too much time to retype all the text with only one hand.

Can you write a program to help the coach salvage his text?

Input

The input file consists of several lines of text, representing the text typed by the coach on a QWERTY keyboard layout when he thought he was using a right-handed Dvorak layout. Each line contains no more than 1000 alphanumeric characters, spaces, and punctuation found on the keyboard.

Output

For each line in the input, your program should write the line of text that the coach had meant to type. In other words, output the text as if it had been keyed using a right-handed Dvorak layout.

Sample Input

Hg66t Mty6k!
Jhg 4ibl; pytmn 8tc 5i79urrr
t,gy jhg 6fxo kt.r

Output for the Sample Input

Hello World!
The quick brown fox jumps...
over the lazy dog.

Sonny Chan
Calgary Collegiate Programming Contest 2006

#include <stdio.h>

int main() {
    char QWERTY[] = "1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
    char DVOARK[] = "123qjlmfp/[]456.orsuyb;=\\789aehtdck-0zx,inwvg'";
    char M1[] = "!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?";
    char M2[] = "!@#QJLMFP?{}$%^>ORSUYB:+|&*(AEHTDCK_)ZX<INWVG\"";
    char cmd[1024];
    int i, j;
    while(gets(cmd)) {
        for(i = 0; cmd[i]; i++) {
            int flag = 0;
            for(j = 0; QWERTY[j]; j++)
                if(QWERTY[j] == cmd[i])
                    putchar(DVOARK[j]), flag = 1;
            for(j = 0; M1[j]; j++)
                if(M1[j] == cmd[i])
                    putchar(M2[j]), flag = 1;
            if(!flag)   putchar(cmd[i]);
        }
        puts("");
    }
    return 0;
}

台長: Morris
人氣(2,015) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][stack] 11111 - Generalized Matrioshkas
此分類上一篇:[UVA][BWT逆轉換] 741 - Burrows Wheeler Decoder

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文