[백준 알고리즘] 2953번: 나는 요리사다

2953번: 나는 요리사다

"나는 요리사다"는 다섯 참가자들이 서로의 요리 실력을 뽐내는 티비 프로이다. 각 참가자는 자신있는 음식을 하나씩 만들어오고, 서로 다른 사람의 음식을 점수로 평가해준다. 점수는 1점부터 5점까지 있다. 각 참가자가 얻은 점수는 다른 사람이 평가해 준 점수의 합이다. 이 쇼의 우승자는 가장 많은 점수를 얻은 사람이 된다. 각 참가자가 얻은 평가 점수가 주어졌을 때, 우승자와 그의 점수를 구하는 프로그램을 작성하시오.

접근 방법:

이것도 단순한 문제. 그냥 총점을 배열에 집어넣고 최댓값의 인덱스를 찾으면 된다.

통과 코드:

#include <iostream>
#include <algorithm>

using namespace std;

int winner(int * scores);
int main(){
    int scores[5] = {0};

    for (int i = 0 ; i < 5 ; i ++){
        for (int j = 0 ; j < 4 ; j++){
            int score;
            cin >> score;
            scores[i] += score;
        }
      cout << "\nscores: " << scores[i] << endl;
    }
    int w = winner(scores);
    cout << w+1 << " "<< scores[w] << endl;

    return 0;
}

int winner(int * scores){
    int winneridx = 0;
    int winnerscore =  scores[0];
    for (int i = 0 ; i < 5 ; i++){
        if (winnerscore < scores[i]){
            winnerscore = scores[i];
            winneridx = i;
        }
    }
    return winneridx;
}

Written by@전여훈 (Click Me!)
고민이 담긴 코드를 만들자, 고민하기 위해 공부하자.