Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <set>
  2. #include <map>
  3. #include <string>
  4. #include <iostream>
  5.  
  6. int main() {
  7. unsigned int T;
  8. std::cin >> T;
  9. std::map<char, std::set<char>> data;
  10. while(T--) {
  11. std::string line = "abc";
  12. std::cin >> line;
  13. data[line[0]];
  14. for(unsigned int i = 1; i < line.size(); i++) {
  15. data[line[i]].insert(line[i - 1]);
  16. }
  17. }
  18. std::string result;
  19. while(!data.empty()) {
  20. auto emptySet = data.begin();
  21. while(emptySet != data.end() && !emptySet -> second.empty()) {
  22. emptySet++;
  23. }
  24. if(emptySet == data.end()) {
  25. result = "SMTH WRONG";
  26. break;
  27. }
  28. auto current = emptySet -> first;
  29. result += current;
  30. data.erase(current);
  31. for(auto& p : data) {
  32. p.second.erase(current);
  33. }
  34. }
  35. std::cout << result << std::endl;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement