forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10030.cpp
97 lines (92 loc) · 1.41 KB
/
10030.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
89
90
91
92
93
94
95
96
97
#include <bits/stdc++.h>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
class state
{
public:
#define FILE 1
#define EXT 0
string in;
int data[2];
bool is_exist;
};
int check[1000];
void solve(int n, int m, state *in)
{
int cnt = n;
rep(k, m)
{
fill(check, check + n, 0);
rep(i, n)
{
if (in[i].is_exist == true)
{
check[in[i].data[k % 2]]++;
}
}
rep(i, n)
{
if (in[i].is_exist == true && check[in[i].data[k % 2]] == 1)
{
in[i].is_exist = false, cnt--;
}
}
}
cout << cnt << endl;
rep(i, n) if (in[i].is_exist == true)
{
cout << in[i].in << endl;
}
}
int main()
{
int te, tc = 0;
cin >> te;
while (te--)
{
if (tc)
{
puts("");
}
tc++;
int n, m;
cin >> n >> m;
map<string, int> File, Ext;
state in[n];
rep(i, n)
{
in[i].is_exist = true;
cin >> in[i].in;
int p = 0;
string f = "", e = "";
while (p < in[i].in.size() && in[i].in[p] != '.')
{
f += in[i].in[p++];
}
p++;
while (p < in[i].in.size())
{
e += in[i].in[p++];
}
if (File.find(f) != File.end())
{
in[i].data[FILE] = File[f];
}
else
{
in[i].data[FILE] = File.size(), File[f] = in[i].data[FILE];
}
if (Ext.find(e) != Ext.end())
{
in[i].data[EXT] = Ext[e];
}
else
{
in[i].data[EXT] = Ext.size(), Ext[e] = in[i].data[EXT];
}
}
solve(n, m, in);
}
return 0;
}