先把鍵盤輸入成一個字元陣列,這樣比較好轉換。
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;
}