본문 바로가기

Algorithm

(C++) - 백준(BOJ) 2476 : 주사위 게임 답

반응형
#include <iostream>
using namespace std;
int main() {
    int  arr[3], cnt = 0, big = 0, last = 0, T, score = 0;
    cin >> T;
    for (int i = 0; i < T; i++)
    {
        for (int i = 0; i < 3; i++)
        {
            cin >> arr[i];
        }
        for (int i = 0; i < 2; i++)//같은게 있는지 찾음
        {
            for (int j = i + 1; j < 3; j++)
            {
                if (arr[i] == arr[j])
                    cnt++;
            }
        }
        switch (cnt)
        {
        case 3:
            score = 10000 + arr[0] * 1000;
            if (score > last)
                last = score;
            break;
        case 1:
            for (int i = 0; i < 2; i++)//같은게 있는지 찾음
            {
                for (int j = i + 1; j < 3; j++)
                {
                    if (arr[i] == arr[j])
                    {
                        score = 1000 + arr[i] * 100;
                        if (score > last)
                            last = score;
                        break;
                    }
                }
            }
            break;
        case 0:
            for (int i = 0; i < 3; i++)
            {
                if (arr[i] > big)
                    big = arr[i];
            }
            score = 100 * big;
            if (score > last)
                last = score;
            break;
        }
        cnt = 0;
        big = 0;

    }
    cout << last << '\n';
}