-
Notifications
You must be signed in to change notification settings - Fork 0
/
whatdoesthefoxsay.cpp
69 lines (58 loc) · 1.78 KB
/
whatdoesthefoxsay.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Get the number of test cases
int t;
cin >> t;
cin.ignore(256, '\n');
// For each test case
while(t-- > 0)
{
// Get the line with the noises
string line;
getline(cin, line);
vector<string> noises; // Stores the noises
// Put each noise into the vector
char *noise;
noise = strtok(const_cast<char*>(line.c_str()), " ");
while(noise != nullptr)
{
noises.push_back(string(noise));
noise = strtok(nullptr, " ");
}
// For each animal that makes a noise
getline(cin, line);
while(line != "what does the fox say?")
{
// Get the start of the line
noise = strtok(const_cast<char*>(line.c_str()), " ");
noise = strtok(nullptr, " ");
// Get the noises that animal makes
noise = strtok(nullptr, " ");
while(noise != nullptr)
{
// While that noise can be found in the vector of noises
auto it = find(noises.begin(), noises.end(), string(noise));
while(it != noises.end())
{
// Remove that noise from the vector
noises.erase(it);
it = find(noises.begin(), noises.end(), string(noise));
}
// Get the next noise
noise = strtok(nullptr, " ");
}
// Get the next animal
getline(cin, line);
}
// For each noise left in the vector of noises
for(string s : noises)
{
// Print that noise
cout << s << " ";
}
cout << endl;
}
return 0;
}