-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindDistinctElements.cpp
More file actions
46 lines (45 loc) · 944 Bytes
/
findDistinctElements.cpp
File metadata and controls
46 lines (45 loc) · 944 Bytes
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
#include <iostream>
#include <vector>
#include <unordered_set>
#include <map>
using namespace std;
int main()
{
int tc;
cin >> tc;
while (tc--)
{
int n;
cin >> n;
int cnt = 0;
vector<vector<int>> v(n, vector<int>(n, 0));
map<int, int> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> v[i][j];
}
}
for (int i = 0; i < n; i++)
{
unordered_set<int> s;
for (int j = 0; j < n; j++)
{
s.insert(v[i][j]);
}
for (auto i = s.begin(); i != s.end(); i++)
{
m[*i]++;
}
}
for (auto i = m.begin(); i != m.end(); i++)
{
if (i->second == n)
{
cnt++;
}
}
cout << cnt << "\n";
}
}