【題解】ZeroJudge e578: 10222 – Decode the Mad man

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e578 (考生答對率: 33.11%)
【解題想法】

  • 字母皆為小寫,空白和換行請直接輸出。
  • 利用map紀錄字元間的對應關係。後續處理直接查表。
  • (Line-10) 「\」需加上跳脫字元,以「\\」表示。
#include <iostream>
#include <map>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s[] = {"~!@#$%^&*()_+",
        "`1234567890-=",
        "qwertyuiop[]\\",
        "asdfghjkl;'",
        "zxcvbnm,./"};
    
    map <char, char> mp;
    for (int i = 0; i < 5; i++){
        for (int j = 2; j < s[i].size(); j++){
            mp[s[i][j]] = s[i][j-2];
        }
    }
    string S;
    while (getline(cin, S)){
        for (int i = 0; i < S.size(); i++){
            if (S[i] == ' ') cout << " ";
            else cout << mp[S[i]];
        }
        cout << "\n";
    }
    return 0;
}
分享本文 Share with friends