先建立一個鍵盤keyboard,然後輸入一個字元c之後就找在keyboard裡的index,並輸出keyboard[i-2]。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
沒有留言:
張貼留言