정신과 시간의 방
작성일
2024. 7. 23. 15:48
작성자
risehyun
  • 문제

 

  • 풀이
#include <iostream>

using namespace std;

int main()
{
	int diceInput[3] = {};
	int valueCount[7] = {};
	int result = 0;
	int maxIndex = 0;

	for (int i = 0; i < 3; i++)
	{
		cin >> diceInput[i];
	}

	for (int i = 0; i < 3; i++)
	{
		valueCount[diceInput[i]]++;
	}

	for (int i = 1; i < 7; i++)
	{
		// case 1. 같은 눈이 3개가 나오는 경우
		if (valueCount[i] == 3)
		{
			result = 10000 + (i * 1000);
			break;
		}
		// case 2. 같은 눈이 2개만 나오는 경우
		else if (valueCount[i] == 2)
		{
			result = 1000 + (i * 100);
			break;
		}
		// case 3. 모두 다른 눈이 나오는 경우
		else
		{
			// 그 중 가장 큰 눈을 골라냄
			// 반복문을 돌다보면 maxIndex에 가장 마지막으로 1로 카운팅 된 값이 
			// 들어가게 되므로 가장 큰 눈의 index이 max값이 됨
			if (valueCount[i] == 1)
			{
				maxIndex = i;
			}

			result = maxIndex * 100;
		}

	}

	cout << result;

	return 0;
}

 

  • 메모
    중복 되는 숫자를 찾기 위해 valueCount를 사용했다.
    이때 diceInput[i] 에 해당하는 주사위 값 자체를 인덱스로 사용해서 입력받은 값을 쉽게 비교할 수 있도록 만들었다.