Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-07-23

SuperRot

| 05:33

問題文

暗号化された文字列を復号。

class SuperRot {
public:
    string decoder(string message) {
        setToTable('A', 'M', 'N');
        setToTable('N', 'Z', 'A');
        setToTable('a', 'm', 'n');
        setToTable('n', 'z', 'a');
        setToTable('0', '4', '5');
        setToTable('5', '9', '0');
        for (int i = 0; i < message.length(); i++) {
            if (isalnum(message[i]))
                message[i] = table[message[i]];
        }
        return message;
    }
private:
    char table[256];
    void setToTable(const char l, const char h, const char s) {
        for (int i = l; i <= h; i++) table[i] = s+(i-l);
    }
};