【題解】ZeroJudge a009: 解碼器

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=a009

#include <iostream>
using namespace std;

int main() {
    int k = -7;
    string s;

    while(getline(cin, s)) {
        int len = s.length();
        for (int i=0; i<len; i++)
            s[i] = s[i] + k;
        cout << s << endl;
    }
}

Python code (credit: Amy Chou)

k = -7

while True:
    try:
        s = input()
        ans = ""
        for i in range(len(s)):
            ans += chr(ord(s[i]) + k)
        print(ans)
    except:
        break
分享本文 Share with friends