ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 11655 - ROT13
    백준 algorithm 2020. 3. 11. 23:10

    문제 설명

     

     

    => 공백이 포함된 문자열을 입력받아 각 문자마다 아스키코드로 13을 더해주면 된다. 

    => 소문자와 대문자의 범위를 벗어날 때의 예외처리를 해주어야한다.

    => 본인은 소문자의 아스키코드를 int형으로 받아 따로 처리해주었다. 

     

     

     

    //
    //  main.cpp
    //  Baekjoon
    //
    //  Created by 이준후
    //  Copyright © 2020 이준후. All rights reserved.
    //
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        
        string s;
        getline(cin, s);
        
        for(int i=0; i<s.length(); ++i)
        {
            if( (s[i]>= 65 && s[i]<= 90 ) ) //case Big Letter
            {
                
                s[i] +=13;
                if(s[i]>90)
                {
                    int tmp= s[i]%90;
                    s[i]=64+tmp;
                }
            }
            else if( s[i]>= 97 && s[i]<= 122 ) //case Small Letter
            {
                int index= s[i];
                index+=13;
                if(index >122)
                {
                    int tmp=index % 122;
                    s[i] = 96+tmp;
                }
                else{
                    s[i]=index;
                }
            }
            else continue; //case not alphabet
            
        };
        cout<<s<<'\n';
        return 0;
    }
    
    

    '백준 algorithm' 카테고리의 다른 글

    백준 11656 - 접미사 배열  (0) 2020.03.13
    백준 10824 - 네 수  (0) 2020.03.11
    백준 10820 - 문자열 분석  (0) 2020.03.10
    백준 10808 - 알파벳 개수  (0) 2020.03.10
    백준 1850 - 최대공약수  (0) 2020.03.10

    댓글

Designed by Who.