์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[๋ฐฑ์ค€(BOJ)] 11655๋ฒˆ: ROT13 (C++)

PROGRAMMING/Algorithm

by koharin 2021. 8. 30. 18:06

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ๋ฌธ์ œํ’€์ด ๊ณผ์ •


๋ฌธ์ž + 13์„ ํ–ˆ์„ ๋•Œ ์•„์Šคํ‚ค ์ฝ”๋“œ์˜ ๋Œ€๋ฌธ์ž ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๊ฑฐ๋‚˜, ์†Œ๋ฌธ์ž ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋‹ค์‹œ A๋ถ€ํ„ฐ ๋˜๋Š” a๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋„๋ก ์—ฐ์‚ฐ์„ ํ•ด์คฌ๋‹ค.

๋Œ€๋ฌธ์ž ์†Œ๋ฌธ์ž์— ๋”ฐ๋ผ ์—ฐ์‚ฐ์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— isupper, islower๋กœ ์ผ€์ด์Šค๋ฅผ ๋‚˜๋ˆ ์„œ ์ง„ํ–‰ํ–ˆ๋‹ค.

 

 

๐Ÿ’ป ์ฝ”๋“œ


#include <bits/stdc++.h>
using namespace std;
int main(){
    string str; getline(cin, str);
    for(int i=0; i<str.size(); i++){
        if(isupper(str[i])){
            if(str[i] + 13 > 90) str[i] = 65 + (str[i] + 13 - 90) - 1;
            else str[i] += 13;
        }
        else if(islower(str[i])){
            if(str[i] + 13 > 122) str[i] = 97 + (str[i] + 13 - 122) - 1;
            else str[i] += 13;
        }
        printf("%c", str[i]);
    }

}

 

 

๐Ÿ“„ ์ œ์ถœ๊ฒฐ๊ณผ


728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ