Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- using namespace std;
- int main() {
- map <string, set <string>> voc;
- string s, en, lt;
- int n, k = 0;
- cin >> n;
- for (int i = 0; i < n; i++) {
- getline(cin, s);
- k = s.find("-");
- en = s.substr(0, k - 2);
- s = s.substr(k + 2) + ",";
- k = -1;
- while (s.find(",", k + 1) != -1) {
- lt = s.substr(k + 1, s.find(",", k + 1) - k - 1);
- if (voc.find(lt) != voc.end()) {
- voc.insert(pair <string, set <string>> (lt, {en}));
- }
- else {
- voc[lt].insert(en);
- }
- if (s.size() - 1 != s.find(",", k + 1)){
- k = s.find(",", k + 1);
- }
- else {
- break;
- }
- }
- }
- for (auto a : voc) {
- cout << a.first << " - ";
- for (auto b : a.second) {
- cout << b;
- if (b == *a.second.rbegin()) {
- break;
- }
- cout << ",";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement