[BOJ][브1][15904] UCPC는 무엇의 약자일까?

문제 링크

문제링크

첫 번째 풀이 : Greedy

알고리즘

하나씩 비교해서 존재하는지 판단합니다.

정답코드

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
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MAX = 5010;
const int MOD = 10007;
int arr[MAX][MAX];
ll dp[MAX][2];
bool visited[MAX];

int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };

int n, m;

void show(void);
void bfs(int x, int y);

char ucpc[] = { 'U','C','P','C' };

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    getline(cin, s);
    int index = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == ucpc[index]) {
            index++;
            if (index == 4) {
                cout << "I love UCPC";
                return 0;
            }
        }
    }
    cout << "I hate UCPC";
    return 0;
}

Success Notice: 수고하셨습니다. :+1:

Leave a comment