#UVa:10222-Decode the Mad man

灆洢 2011-12-01 22:47:54

先把鍵盤輸入成一個字元陣列,這樣比較好轉換。

C++(0.016)

/*******************************************************/
/* UVa 10222 Decode the Mad man                        */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2011/12/01                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
  const char keyboard[] = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
  const int kblength = strlen( keyboard );
  string s;

  while( getline( cin, s ) ){
    for( int i = 0 ; i < s.length() ; i++ )
      if( s[i] == ' ' )
        printf( " " );
      else
        for( int j = 0 ; j < kblength ; j++ )
          if( keyboard[j] == s[i] ){
            printf( "%c", keyboard[j-2] );
            break;
          }
    printf( "\n" );
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料