Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

hwooo

BOJ (C/C++) 1233번: 주사위 본문

Study/Algorithm

BOJ (C/C++) 1233번: 주사위

hwooo 2022. 11. 30. 02:39

https://www.acmicpc.net/problem/1233

 

1233번: 주사위

지민이는 주사위 던지기 게임을 좋아하여 어느 날 옆에 있는 동호를 설득하여 주사위 던지기 게임을 하자고 하였다. 총 3개의 주사위가 있다. 그리고 이 주사위는 각각 S1(2 ≤ S1 ≤ 20), S2(2 ≤ S2

www.acmicpc.net


풀이

각 주사위에서 나올 수 있는 숫자만큼 반복문을 실행하여 해당 숫자 값이 나올 때 횟수를 증가시켜줌.


코드

#include <stdio.h>
int main() {
	int s1, s2, s3, max = 0, max_i = 0;
	int cnt[81] = { 0, };
    
	scanf("%d %d %d", &s1, &s2, &s3);
    
	for (int i = 1; i <= s1; i++) {
		for (int j = 1; j <= s2; j++) {
			for (int k = 1; k <= s3; k++) {
				cnt[i + j + k]++;
			}
		}
	}
    
	for (int i = 1; i <= s1 + s2 + s3; i++) {
		if (max < cnt[i]) max = cnt[i], max_i = i;
	}
    
	printf("%d", max_i);
	return 0;
}