취미로 음악을 하는 개발자

[C++] 백준 2480. 주사위 세개 본문

공대인/Nojam

[C++] 백준 2480. 주사위 세개

영월특별시 2019. 4. 24. 10:45
728x90





#include <iostream>

#include <list>

#include <algorithm>

using namespace std;


int main() {

    list<int> arr;

    list<int>::iterator it;

    int temp;

    int max = 0;

    int same = 0;

    for (int i = 0; i < 3; i++) {

        cin >> temp;

        if (max < temp)

            max = temp;

        it = find(arr.begin(), arr.end(), temp);

        if (it != arr.end()) 

            same = temp;

        else

            arr.push_back(temp);    

    }


    if (arr.size() == 3) {

        cout << max * 100 << endl;

    }


    else if (arr.size() == 2) {

        cout << 1000+(same*100) << endl;

    }


    else {

        cout << 10000+(same*1000) << endl;

    }

}


// 참고

// https://twpower.github.io/78-how-to-use-list-in-cpp

// http://blog.naver.com/PostView.nhn?blogId=cra2yboy&logNo=90125524948


저는 리스트를 만들어서 중복되지 않게 넣었습니다.

주사위를 던진 눈의 개수가 리스트에 있다면 넣지않고, 없으면 넣는데 이걸로 리스트 크기가 정해질 것이고 그것은 곧 중복 개수를 알 수 있습니다.

3이면 중복이 없는 것이고, 2이면 중복이 2개, 1이면 다 중복되는 것입니다.


그리고 중복이 없는 경우에는 주사위 눈의 큰 수를 알아야하므로 주사위를 던질 때마다 큰 수를 알아야하고 중복도 마찬가지입니다.



Comments