본문 바로가기

Algorithm

(C++) - 백준(BOJ) 10708번 : 크리스마스 파티

반응형
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
32
33
34
35
36
37
38
39
#include <iostream>
#include <cstring>
using namespace std;
int a[101],b[101],ans[101];
 
int main() {
    int m,n,target=0;
    cin >> n >> m;//n : 친구들의 수, m : 게임의 횟수
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i]; //매판 타겟
    }
 
    for (int i = 1; i <= m; i++)
    {
        target = a[i];
        int cnt = 0;
        for (int j = 1; j <= n; j++)
        {
            cin >> b[j];
        }
        for (int j = 1; j <= n; j++)
        {
            if (target == b[j])
            {
                ans[j]++;
            }
            else
                cnt++;
 
        }
        //마지막에 못맞춘 사람들만큼 타겟은 점수를 더 얻는다.
        ans[a[i]] += cnt;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << '\n';
    }
}
cs