본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 9288 : More Dice

반응형

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

 

9288번: More Dice

For each case, output the line “Case x:” where x is the case number, on a single line. Then output a list of possible dice-pairs that result in that sum, one on each line. Each dice-pair should be comma-separated and enclosed by parentheses. In each pa

www.acmicpc.net

간단한 출력문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case t, sum을 선언 후 적절히 입력받습니다.

📔 풀이과정

j를 1 ~ sum/2 범위로 for loop를 수행합니다. 한쪽은 j 다른 한 쪽은 sum - j 로 표현될 수 있습니다. 

📔 정답출력

형식에 맞게 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, sum;
int main(){
  cin >> t;
  for(int i = 1; i <= t; i++){
    cin >> sum;
    printf("Case %d:\n", i);
    for(int j = 1; j <= sum/2; j++){
      if(sum-j > 6) continue;
      printf("(%d,%d)\n", j, sum-j);
    }
  }
}

📕 Test Case

1
12
Case 1:
(6,6)

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.