알고리즘/BOJ

백준 16205번 변수명

꾸준함. 2018. 11. 5. 00:47

문제 링크입니다: https://www.acmicpc.net/problem/16205


간단한 문자열 파싱 문제였습니다.


#include <iostream>

#include <string>

using namespace std;

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        int num;

        string s;

        cin >> num >> s;

 

        switch (num)

        {

        case 1:

                 cout << s << "\n";

                 for (int i = 0; i < s.length(); i++)

                         if (s[i] >= 'A' && s[i] <= 'Z')

                         {

                                 cout << "_";

                                 cout << (char)(s[i] - 'A' + 'a');

                         }

                         else

                                 cout << s[i];

                 cout << "\n";

                 s[0] = s[0] - 'a' + 'A';

                 cout << s << "\n";

                 break;

        case 2:

                 for (int i = 0; i < s.length(); i++)

                         if (s[i] == '_')

                         {

                                 cout << char(s[i + 1] - 'a' + 'A');

                                 i++;

                         }

                         else

                                 cout << s[i];

                 cout << "\n";

                 cout << s << "\n";

                 s[0] = s[0] - 'a' + 'A';

                 for (int i = 0; i < s.length(); i++)

                         if (s[i] == '_')

                         {

                                 cout << (char)(s[i + 1] - 'a' + 'A');

                                 i++;

                         }

                         else

                                 cout << s[i];

                 cout << "\n";

                 break;

        case 3:

                 s[0] = s[0] - 'A' + 'a';

                 cout << s << "\n";

                 for (int i = 0; i < s.length(); i++)

                         if (s[i] >= 'A' && s[i] <= 'Z')

                         {

                                 cout << "_";

                                 cout << (char)(s[i] - 'A' + 'a');

                         }

                         else

                                 cout << s[i];

                 cout << "\n";

                 s[0] = s[0] - 'a' + 'A';

                 cout << s << "\n";

                 break;

        }

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 2234번 성곽  (0) 2018.11.05
백준 11723번 집합  (0) 2018.11.05
백준 1929번 소수 구하기  (0) 2018.11.04
백준 3184번 양  (0) 2018.11.04
백준 2617번 구슬 찾기  (0) 2018.11.04