ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 2957번: 창영이의 일기장
    문자열(String) 2018. 7. 19. 20:41
    반응형

    https://www.acmicpc.net/problem/2954


    1. 문제

    창영이는 매일 밤 하루동안 일어난 일을 일기장에 남긴다. 일기장을 쓰면서 영어 공부도 같이 하기 위해서 영어로 일기를 쓴다. 또, 남들이 자신의 일기장을 보는 것을 막기 위해서 모음('a','e','i','o','u')의 다음에 'p'를 하나 쓰고,  그 모음을 하나 더 쓴다.


    예를 들어, "kemija" 는 "kepemipijapa"가 되고, "paprika"는 "papapripikapa"가 된다.


    창영이가 일기장에 작성한 문장이 하나 주어졌을 때, 원래 문장은 무엇인지 구하는 프로그램을 작성하시오.


    2. 알고리즘

    키워드 - 문자열


    3. 코드


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <list>
    #include <queue>
    #include <deque>
    #include <map>
    #include <set>
    #include <stack>
    #include <cstring>
    #include <math.h>
     
    using namespace std;
     
    #define MAX_SIZE 100
    #define INF 0x7fffffff
    #define CENDL "\n"
    #define ll long long
     
    bool solve(char s) {
        string ss("aeiou");
        const int size = ss.size();
     
        for (int i=0;i<size; i++) {
            if (s == ss[i]) {
                return true;
            }
        }
        return false;
    }
    int main() {
     
        cin.tie(0);
        std::ios::sync_with_stdio(false);
     
        string s;
     
        getline(cin, s);
     
        const int size = s.size();
     
        int index = 0;
        string sol;
        while (size > index) {
     
            if (solve(s[index]))
            {
                sol.push_back(s[index]);
                index+=3;
                continue;
            }
            sol.push_back(s[index]); index++;
     
        }
     
        cout << sol << CENDL;
        return 0;
    }
     
    cs



    반응형

    '문자열(String)' 카테고리의 다른 글

    백준 2703번: Cryptoquote  (0) 2018.07.27
    백준 3059번: 등장하지 않는 문자의 합  (0) 2018.07.20
    백준 2902번: KMP는 왜 KMP일까?  (0) 2018.07.03
    백준 2675번: 문자열 반복  (0) 2018.07.03
    백준 2857번: FBI  (0) 2018.06.29

    댓글

Designed by Tistory.