Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #include <map>
- #include <string>
- #include <iostream>
- int main() {
- unsigned int T;
- std::cin >> T;
- std::map<char, std::set<char>> data;
- while(T--) {
- std::string line = "abc";
- std::cin >> line;
- data[line[0]];
- for(unsigned int i = 1; i < line.size(); i++) {
- data[line[i]].insert(line[i - 1]);
- }
- }
- std::string result;
- while(!data.empty()) {
- auto emptySet = data.begin();
- while(emptySet != data.end() && !emptySet -> second.empty()) {
- emptySet++;
- }
- if(emptySet == data.end()) {
- result = "SMTH WRONG";
- break;
- }
- auto current = emptySet -> first;
- result += current;
- data.erase(current);
- for(auto& p : data) {
- p.second.erase(current);
- }
- }
- std::cout << result << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement