Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <vector>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- map<string, vector<string>> dict;
- for (int i = 0; i <= n; i++) {
- string s;
- getline(cin, s);
- string tmp = "";
- vector<string> tmp1(0);
- int x = 0, y = 0;
- for (int j = 0; j < s.length(); j++) {
- if (s[j] == '-') {
- y = j - 2;
- tmp = s.substr(x, y + 1-x);
- x = j + 2;
- }
- else if (s[j] == ',') {
- y = j - 1;
- tmp1.push_back(s.substr(x, y + 1-x));
- x = j + 2;
- }
- else if (j == s.length() - 1) {
- tmp1.push_back(s.substr(x, j + 1 - x));
- }
- }
- dict[tmp] = tmp1;
- }
- set<string> xin;
- for (auto now : dict) {
- for (auto now1 : now.second) {
- xin.insert(now1);
- }
- }
- cout << xin.size() << endl;
- for (auto now : xin) {
- vector<string> tmp(0);
- for (auto now1 : dict) {
- for (auto now2 : now1.second) {
- if (now == now2) {
- tmp.push_back(now1.first);
- }
- }
- }
- cout << now<<" - ";
- for (auto now3 : tmp) {
- if (now3 == tmp[tmp.size() - 1]) cout << now3;
- else cout << now3 << ", ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement