-
Notifications
You must be signed in to change notification settings - Fork 0
/
erase simillar word by set.txt
70 lines (52 loc) · 1.29 KB
/
erase simillar word by set.txt
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
Monk's birthday is coming this weekend! He wants to plan a Birthday party and is preparing an invite list with his friend Puchi. He asks Puchi to tell him names to add to the list.
Puchi is a random guy and keeps coming up with names of people randomly to add to the invite list, even if the name is already on the list! Monk hates redundancy and hence, enlists the names only once.
Find the final invite-list, that contain names without any repetition.
Input:
First line contains an integer T. T test cases follow.
First line of each test contains an integer N, the number of names that Puchi pops up with.
Output:
For each testcase,Output the final invite-list with each name in a new line. The names in the final invite-list are sorted lexicographically.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 105
1 ≤ Length of each name ≤ 105
Sample Input
1
7
chandu
paro
rahul
mohi
paro
arindam
rahul\
Sample Output
arindam
chandu
mohi
paro
rahul
solution
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
set < string > s;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string p;
cin >> p;
s.insert(p);
}
for(auto it = s.begin(); it != s.end(); it++)
{
cout << (*it) << endl;
}
}
}