๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 14720๋ฒˆ - ์šฐ์œ  ์ถ•์ œ

by dkswnkk 2021. 11. 11.

๋ฌธ์ œ

 

14720๋ฒˆ: ์šฐ์œ  ์ถ•์ œ

์˜ํ•™์ด๋Š” ๋”ธ๊ธฐ์šฐ์œ , ์ดˆ์ฝ”์šฐ์œ , ๋ฐ”๋‚˜๋‚˜์šฐ์œ ๋ฅผ ์ข‹์•„ํ•œ๋‹ค. ์ž…๋ง›์ด ๋งค์šฐ ๊นŒ๋‹ค๋กœ์šด ์˜ํ•™์ด๋Š” ์ž์‹ ๋งŒ์˜ ์šฐ์œ ๋ฅผ ๋งˆ์‹œ๋Š” ๊ทœ์น™์ด ์žˆ๋‹ค. ๋งจ ์ฒ˜์Œ์—๋Š” ๋”ธ๊ธฐ์šฐ์œ ๋ฅผ ํ•œ ํŒฉ ๋งˆ์‹ ๋‹ค. ๋”ธ๊ธฐ์šฐ์œ ๋ฅผ ํ•œ ํŒฉ ๋งˆ์‹  ํ›„

www.acmicpc.net

 

์ฝ”๋“œ

#include <iostream>
using namespace std;
int N, checkMilk,cnt;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    while (1) {
        cin >> checkMilk;
        if (checkMilk == 0)    break;
        else N--;
    }
    cnt++;
    for (int i = 0; i < N; i++) {
        int milk; cin >> milk;
        if (checkMilk == 0 && milk == 1) {
            cnt++;
            checkMilk = milk;
        }
        else if (checkMilk == 1 && milk == 2) {
            cnt++;
            checkMilk = milk;
        }
        else if (checkMilk == 2 && milk == 0) {
            cnt++;
            checkMilk = milk;
        }
    }
    cout << cnt;
}

๋Œ“๊ธ€