본문 바로가기

문제 풀이/문제 풀이(BOJ)

[Silver V] UCPC는 무엇의 약자일까? - 15904

[문제 위치]

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

[문제 풀이]

그리디 기법으로 조건을 만족하는게 있는지마다 확인하여 문제를 풀었다.

 

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string sheeped = "UCPC";
    string not_sheep;
    int pos = 0;
    getline(cin, not_sheep);
    for(char curr : not_sheep){
        if(sheeped[pos]==curr){
            pos++;
        }
        if(pos==4) break;
    }
    
    if(pos==4) cout << "I love UCPC";
    else cout << "I hate UCPC";
    

    return 0;
}

 

위의 표와 같은 방식으로 동작하게 된다.