백준 2851번 : 슈퍼마리오

Se0ng_1l·2022년 6월 21일
0

백준

목록 보기
4/40

10개의 입력한 값을 차곡차곡 더해서 100이상이 넘어가는 시점
이전의 합과 이후의 값 중 100에 가장 가까운 숫자를 출력하는 문제
만약, 두 수가 100에 가까운 크기가 같다면 가장 가까운 숫자를 출력

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

#include <iostream>
using namespace std;

int main()
{
    int mush[10];
    for(int i = 0; i < 10; i++)
    {
        cin >> mush[i];
    }
    int aScore = 0;
    int bScore = 0;
    int i = 0;
    while(i < 10)
    {
        aScore += mush[i];
        if(aScore >= 100)
        {
            break;
        }
        bScore += mush[i];
        i++;
    }
    int a = abs(aScore - 100);
    int b = abs(bScore - 100);
    if(a<b)
        cout << aScore;
    else if(a>b)
        cout << bScore;
    else
        cout << ((aScore > bScore) ? aScore : bScore);


}
profile
치타가 되고 싶은 취준생

0개의 댓글