프로그래머스
순위 C++
by paysmile
2019. 9. 30.
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int solution(int n, vector<vector<int>> results) {
int answer = 0;
int win[101][101];
memset(win, 0, sizeof(win));
for (int i = 0; i < results.size(); i++)
win[results[i][0]][results[i][1]] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (win[j][i]==1 && win[i][k]==1)
win[j][k] = 1;
}
}
}
for (int i = 1; i <= n; i++) {
int counts = 0;
for (int j = 1; j <= n; j++) {
counts += (win[i][j] + win[j][i]);
}
if (counts == n - 1)
answer++;
}
return answer;
}