網頁

2014年2月17日 星期一

UVa 10222 Decode the Mad man

想法:
  先建立一個鍵盤keyboard,然後輸入一個字元c之後就找在keyboard裡的index,並輸出keyboard[i-2]。



#include <cstdio>
#include <cctype>
using namespace std;
const char keyboard[] = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
int main()
{
char c;
while (scanf("%c",&c) != EOF){
c = tolower(c); //換成小寫字母
if (isspace(c)) printf("%c",c); //如果為' '或'\n'直接輸出
else{
for (int i=0; keyboard[i]; ++i)
if (c == keyboard[i]){
printf("%c",keyboard[i-2]);
break;
}
}
}
return 0;
}

沒有留言:

張貼留言