Advertisement
shek_shek

2050

Oct 7th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stack>
  3. #include <math.h>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string.h>
  7. #include <string>
  8. #include <set>
  9. #include <memory.h>
  10. #include <vector>
  11. #include <map>
  12. #include <queue>
  13. #include <iomanip>
  14. #include <ctime>
  15. #include <cassert>
  16.  
  17.  
  18.  
  19. #define forn(i, n) for (int i = 0; i < int(n); i++)
  20. #define ll long long
  21. #define mp(a, b) make_pair(a, b)
  22. #define sqr(x) ( (x) * (x) )
  23. #define all(a) a.begin(), a.end()
  24.  
  25. using namespace std;
  26.  
  27. typedef pair <int, int> pt;
  28. typedef long double ld;
  29. const int INF = 1e9;
  30. const ld EPS = 1e-9;
  31.  
  32. map <string, vector <pair <string, string>>> v;
  33.  
  34. int main() {
  35. #ifdef _DEBUG
  36.     freopen("input.txt", "r", stdin);
  37.     freopen("output.txt", "w", stdout);
  38. #endif
  39.     int n;
  40.     cin >> n;
  41.     string section = "";
  42.     getline(cin, section);
  43.     while (n--) {
  44.         string temp, s = "";
  45.         getline(cin, temp);
  46.         forn (i, temp.size()) {
  47.             if (temp[i] != ' ' && temp[i] != '\n')
  48.                 s += temp[i];
  49.         }
  50.         if (s.front() == '[' && s.back() == ']') {
  51.             section = s;
  52.             v[section];
  53.             continue;
  54.         }
  55.         if (s.front() == ';')
  56.             continue;
  57.         string key = "", value = "";
  58.         bool flag = false;
  59.         forn (i, s.size()) {
  60.             if(s[i] == '=') {
  61.                 flag = true;
  62.                 continue;
  63.             }
  64.             if (!flag)
  65.                 key += s[i];
  66.             else
  67.                 value += s[i];
  68.         }
  69.         bool find_key = false;
  70.         for (int i = 0; i < v[section].size(); i++) {
  71.             if (v[section][i].first == key)
  72.                 v[section][i].second = value, find_key = true;
  73.         }
  74.         if (!find_key) {
  75.             v[section].push_back(mp(key, value));
  76.         }
  77.     }
  78.     for (map <string, vector <pair <string, string>>> :: iterator it = v.begin(); it != v.end(); it++) {
  79.         cout << (*it).first;
  80.         if ((*it).first != "")
  81.             cout << endl;
  82.         sort((*it).second.begin(), (*it).second.end());
  83.         for (int i = 0; i < (*it).second.size(); i++) {
  84.             cout << (*it).second[i].first << "=" << (*it).second[i].second << endl;
  85.         }
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement