#UVa:10082 – WERTYU

解法指引

先把鍵盤打成一個陣列,這樣比較好得解。

程式碼(C++:0.012)

10082.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
25
26
/*******************************************************/
/* UVa 10082 WERTYU                                    */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2012/03/23                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
  
int main(){
  const char keyboard[] = "   `1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
  const int kblen = strlen(keyboard);
  char hash[256];
  string s;
   
  for( int i = 2 ; i < kblen ; i++ )
    hash[keyboard[i]] = keyboard[i-1];
   
  while( getline( cin, s ) ){
    for( int i = 0 ; i < s.length() ; i++ )
      printf( "%c", hash[s[i]] );
    printf( "\n" );
  }
  return 0;
}