#UVa:10222-Decode the Mad man

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

C++(0.016)

/*******************************************************/
/* UVa 10222 Decode the Mad man                        */
/* Author: LanyiKnight [at] knightzone.org             */
/* 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;
}

沒有迴響

本文還沒有迴響,快來搶頭香!

發表迴響