Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <string.h>
- #include <string>
- #include <set>
- #include <memory.h>
- #include <vector>
- #include <map>
- #include <queue>
- #include <iomanip>
- #include <ctime>
- #include <cassert>
- #define forn(i, n) for (int i = 0; i < int(n); i++)
- #define ll long long
- #define mp(a, b) make_pair(a, b)
- #define sqr(x) ( (x) * (x) )
- #define all(a) a.begin(), a.end()
- using namespace std;
- typedef pair <int, int> pt;
- typedef long double ld;
- const int INF = 1e9;
- const ld EPS = 1e-9;
- map <string, vector <pair <string, string>>> v;
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n;
- cin >> n;
- string section = "";
- getline(cin, section);
- while (n--) {
- string temp, s = "";
- getline(cin, temp);
- forn (i, temp.size()) {
- if (temp[i] != ' ' && temp[i] != '\n')
- s += temp[i];
- }
- if (s.front() == '[' && s.back() == ']') {
- section = s;
- v[section];
- continue;
- }
- if (s.front() == ';')
- continue;
- string key = "", value = "";
- bool flag = false;
- forn (i, s.size()) {
- if(s[i] == '=') {
- flag = true;
- continue;
- }
- if (!flag)
- key += s[i];
- else
- value += s[i];
- }
- bool find_key = false;
- for (int i = 0; i < v[section].size(); i++) {
- if (v[section][i].first == key)
- v[section][i].second = value, find_key = true;
- }
- if (!find_key) {
- v[section].push_back(mp(key, value));
- }
- }
- for (map <string, vector <pair <string, string>>> :: iterator it = v.begin(); it != v.end(); it++) {
- cout << (*it).first;
- if ((*it).first != "")
- cout << endl;
- sort((*it).second.begin(), (*it).second.end());
- for (int i = 0; i < (*it).second.size(); i++) {
- cout << (*it).second[i].first << "=" << (*it).second[i].second << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement