-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1403.cpp
More file actions
108 lines (82 loc) · 2.1 KB
/
1403.cpp
File metadata and controls
108 lines (82 loc) · 2.1 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//meu avo é famoso
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct player{
int id;
int pontos;
};
bool comp(player x, player y){
return x.pontos < y.pontos;
}
int exist_in_vector(vector<player> v, int id_player){
for(int i=0; i<v.size(); i++){
if(v[i].id == id_player) return i;
}
return -1;
}
vector<player> create_ranking(vector<vector<int>> matriz){
vector<player> r;
for(int linha=0; linha<matriz.size(); linha++){
for(int coluna=0; coluna<matriz[linha].size(); coluna++){
int index = exist_in_vector(r, matriz[linha][coluna]);
if(index != -1){
r[index].pontos++;
} else {
player p;
p.id = matriz[linha][coluna];
p.pontos = 1;
r.push_back(p);
}
}
}
return r;
}
void find_second(vector<player> rank){
vector<int> ids;
int second = 0;
int n = rank.size();
int first = 0;
sort(rank.begin(), rank.end(), comp);
for(int i=0; i<n; i++){
if(rank[i].pontos > first){
first = rank[i].pontos;
}
}
for(int i=0; i<n; i++){
if(rank[i].pontos > second && rank[i].pontos < first){
second = rank[i].pontos;
}
}
for(int i=0; i<n; i++){
if(rank[i].pontos == second){
ids.push_back(rank[i].id);
}
}
sort(ids.begin(), ids.end());
for(auto p : ids){
cout << p << " ";
}
}
int main(){
int n, m;
while(true){
cin >> n >> m;
if(n==0 && m==0) break;
vector<vector<int>> matriz;
for(int i=0; i<n; i++){
vector<int> linha;
for(int j=0; j<m; j++){
int jogador;
cin >> jogador;
linha.push_back(jogador);
}
matriz.push_back(linha);
}
vector<player> ranking = create_ranking(matriz);
find_second(ranking);
cout << endl;
}
return 0;
}