2018年4月12日 星期四

程式設計--UVA10222

ㄟ都,其實不知道這樣有沒有效,不過就當作日記,放上來當筆記寫

網址:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=14&problem=1163&mosmsg=Submission+received+with+ID+21124035

程式碼:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    char c,s[]=
    "`1234567890-="
    "qwertyuiop[]\\"
    "asdfghjkl;'"
    "zxcvbnm,./";
    while(cin.get(c))
    {
        c=tolower(c);
        char *p=strchr(s,c);
        if(p)
            cout<<*(p-2);
        else
            cout << c;
    }
    return 0;
}

我不太知道為甚麼鍵盤對應表那裏第二行的"\\"要放兩個?明明鍵盤只有一個
然後我知道\是跳脫字元,要放兩個//告訴電腦,這是一個普通的/(哎呀 之前上課好像有聽過XD)
不過用指標覺得滿厲害的,用指標指向要找的字元,在往後減二,就可以找到目標,感覺很簡潔


我覺得很滿重要的概念
cin.getl()
中間括號好像是用來放字元的,但不知道數字可不可以

strchr(,)
中間放兩個參數,前面是放要被搜尋的字串,後面是要找的那個字元


參考資料:
http://www.cnblogs.com/flatfoosie/archive/2010/12/22/1914055.html
http://www.cplusplus.com/reference/cstring/strstr/
https://blog.wu-boy.com/2010/08/cc-cstring-string-h-%E5%87%BD%E5%BC%8F%EF%BC%9Astrstr-strchr/

沒有留言:

張貼留言