-
Notifications
You must be signed in to change notification settings - Fork 0
/
topc_catch_suspects_game.cpp
88 lines (74 loc) · 1.35 KB
/
topc_catch_suspects_game.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
inputs:
2
3 4
1 2 3 2
1 1 2
3 2 2
1 1 3
2 2 2
-------------
outputs:
3 | 4| 5
*/
#include <stdio.h>
#define SZ_N 51
#define SZ_G 101
int players[SZ_N];
int suspects[SZ_G];
int N, M;
static void
clear_buf()
{
int i;
for (i = 0; i < N + 1; i++)
players[i] = 0;
for (i = 0; i < M + 1; i++)
suspects[i] = 0;
}
int main()
{
setbuf(stdout, NULL);
int T, tc, i, j;
scanf("%d", &T);
for (tc = 1; tc <= T; tc++)
{
// inputs
scanf("%d%d", &N, &M);
/* Save the suspects info to suspects array*/
for (i = 0; i < M; i++)
scanf("%d", &suspects[i]);
// solve
/* Play games */
for (i = 0; i < M; i++)
{
/* suspect get 1 point always */
int curr_suspt = suspects[i];
players[curr_suspt]++;
/* get the answers from players*/
/* player : 1, 2, 3 ... */
int losers = 0;
for (j = 1; j <= N; j++)
{
int x;
scanf("%d", &x);
/* get the points if answer == suspect in this game */
if (x == curr_suspt && j != curr_suspt)
players[j]++;
/* count players who write wrong answer */
else if (j != curr_suspt)
losers++;
}
/* current suspect gets more points from losers */
players[curr_suspt] += losers;
}
// output
/* print each player's game point */
for (i = 1; i <= N; i++)
printf("%d ", players[i]);
printf("\n");
// clear buffer for next games
clear_buf();
}
return 0;
}