본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 9699 : RICE SACK

반응형

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

 

9699번: RICE SACK

For each test case, the output contains a line in the format Case #x: followed by a sequence of integers, where x is the case number (starting from 1) and an integer that indicates the weight of a rice sack that will go to Al-Ameen.

www.acmicpc.net

간단한 구현문제였습니다.

📕 풀이방법

📔 입력 및 초기화

 1. 테스트 케이스의 수 t, 정답을 출력할 변수 ans를 선언해준 뒤 t에 입력받습니다.

 2. 매 케이스마다 5개의 rice sake를 입력해줍니다. 그 때마다 

📔 풀이과정

매 케이스마다 입력값과 ans중 최댓값을 ans에 저장해줍니다.

📔 정답출력

ans를 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, ans;
int main(){
    cin >> t;
    for(int i = 1; i <= t; i++, ans = 0){
        for(int i = 0, x; i < 5; i++) 
            cin >> x, ans = max(ans, x);
        printf("Case #%d: %d\n", i, ans);
    }
}