Algorithm

[๋ฐฑ์ค€ 11655] ROT13

osean 2023. 4. 3. 20:45

๋ฌธ์ œ

 

11655๋ฒˆ: ROT13

์ฒซ์งธ ์ค„์— ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

www.acmicpc.net

ํ’€์ด

 

๋กœ๊ทธ์ธ

 

www.acmicpc.net

using namespace std;

// ์•”ํ˜ธํ™” > ์•ŒํŒŒ๋ฒณ ์œ„์น˜ +13
// ๋ณตํ˜ธํ™” > ์•”ํ˜ธํ™”๋œ ์•ŒํŒŒ๋ฒณ ์œ„์น˜ +13
// ์˜ˆ์™ธ > ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹Œ ๋ฌธ์ž๋Š” ํŒจ์Šค
// A : 65
// Z : 90
// a : 97
// z : 122

string input;

void encrypt(char c, bool isBig) {
    int start = 'a';
    if (isBig) start = 'A';
    int result = c - start + 13;
    if (26 <= result) result -= 26;
    cout << (char) (result + start);
}

int main() {
    getline(cin, input);

    for (char c: input) {
        if ('A' <= c && c <= 'Z') {
            encrypt(c, true);
        } else if ('a' <= c && c <= 'z') {
            encrypt(c, false);
        } else {
            cout << c;
        }
    }
}