문제 링크입니다: https://www.acmicpc.net/problem/2476
2476번: 주사위 게임
첫째 줄에는 참여하는 사람 수 N이 주어지고 그 다음 줄부터 N개의 줄에 사람들이 주사위를 던진 3개의 눈이 빈칸을 사이에 두고 각각 주어진다.
www.acmicpc.net
문제에서 주어진대로 그대로 코딩하면 되는 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
vector<int> prices(N); | |
for (int i = 0; i < N; i++) | |
{ | |
int a, b, c; | |
cin >> a >> b >> c; | |
int dices[6 + 1] = { 0, }; | |
dices[a]++; | |
dices[b]++; | |
dices[c]++; | |
int sum = 0; | |
bool flag = (a != b) && (b != c) && (c != a); | |
for (int dice = 6; dice >= 1; dice--) | |
{ | |
if (dices[dice] == 3) | |
{ | |
sum += (10000 + dice * 1000); | |
break; | |
} | |
if (dices[dice] == 2) | |
{ | |
sum += (1000 + dice * 100); | |
break; | |
} | |
if (flag && dices[dice] == 1) | |
{ | |
sum += (dice * 100); | |
break; | |
} | |
} | |
prices[i] = sum; | |
} | |
sort(prices.begin(), prices.end()); | |
cout << prices[N - 1] << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2592번 대표값 (0) | 2020.05.03 |
---|---|
백준 2581번 소수 (0) | 2020.05.03 |
백준 17779번 게리맨더링 2 (2) | 2020.04.30 |
백준 17825번 주사위 윷놀이 (0) | 2020.04.30 |
백준 2456번 나는 학급회장이다 (0) | 2020.04.26 |