2017年9月24日 星期日

[UVa]10222 - Decode the Mad man(C++)



#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
char c;
char s[] = "`1234567890-="          //鍵盤對應表
"qwertyuiop[]\\"
"asdfghjkl;'"
"zxcvbnm,./";
while(cin.get(c))                            //結束符只有enter,會把enter放在列隊等待
{
c = tolower(c);                        //字元全變小寫
char *p = strchr(s, c);              //指標指向字元變數c,*p是儲存strchr(s, c)的變數位址
if(p)                                         //如果字元c存在於字串s內,儲存的位置往左兩位,後輸出值
{
cout << *(p-2);
}
else
{
cout << c;                    //否則輸出字元c
}
}
return 0;
}

沒有留言:

張貼留言