Click
Here to go back to the homepage.
What does the fox say? Solution:
#include <bits/stdc++.h>
using namespace std;
std::vector<std::string> stringSplit(const std::string &s, char delimiter){
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (getline(tokenStream, token, delimiter)){
tokens.push_back(token);
}
return tokens;
}
int main() {
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
string line;
getline(cin, line);
int n_cases = stoi(line);
while(n_cases--){
getline(cin, line);
set<string> s;
auto forest_sounds = stringSplit(line, ' ');
for_each(forest_sounds.begin(), forest_sounds.end(), [&s = s](const string &sound){ s.insert(sound);});
while(line != "what does the fox say?"){
getline(cin, line);
s.erase(stringSplit(line, ' ')[2]);
}
forest_sounds.erase(remove_if(forest_sounds.begin(), forest_sounds.end(), [&s = s, end = s.end()](const string &x){ return (s.find(x) == end);}), forest_sounds.end());
for_each(forest_sounds.begin(), forest_sounds.end(), [](const string &s){ cout << s << " ";});
cout << endl;
}
return 0;
}