Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <iterator>
- #include <conio.h>
- #include <stack>
- #include <set>
- using namespace std;
- void show_set(const set <string>& A)
- {
- copy(A.begin(), A.end(), ostream_iterator<string>(cout, " "));
- cout << endl;
- }
- bool isStrDigit(const string& str)
- {
- int ret = 0;
- if ((str[0] == '-') || (str[0] == '+'))
- ret++;
- for (int i = ret; i < str.size(); i++)
- if (!isdigit(str[i]))
- {
- return 0;
- }
- return 1;
- }
- string convertToString(int i)
- {
- string res;
- res.clear();
- stack <char> digit;
- if (i < 0)
- digit.push('-');
- else
- if (i == 0)
- {
- res = '0';
- return res;
- }
- i = abs(i);
- while (i > 0)
- {
- digit.push(i % 10 + 48);
- i = i / 10;
- }
- while (!digit.empty())
- {
- res += digit.top();
- digit.pop();
- }
- return res;
- }
- int main()
- {
- ifstream in("input.txt");
- vector <string> chest;
- set <string> variant;
- multimap <string, int> podch;
- string obj, obj2;
- while (in >> obj)
- {
- chest.push_back(obj);
- }
- for (int i = 0; i < chest.size(); i++)
- {
- if (isStrDigit(chest[i]))
- {
- podch.insert(pair <string, int>(chest[i], i));
- }
- }
- obj.clear();
- obj2.clear();
- for (int i = 0; i < chest.size(); i++)
- {
- auto iterPair = podch.equal_range(chest[i]);
- if (iterPair.first != iterPair.second)
- {
- //cout << "( " << chest[i] << ':';
- obj = '(' + chest[i] + ':';
- for (auto nearIt = iterPair.first; nearIt != iterPair.second; ++nearIt)
- {
- //cout << nearIt->second << ' ';
- obj += convertToString(nearIt->second) + ',';
- }
- //cout << ") ";
- obj += ')';
- obj.erase(obj.size() - 2, 1);
- variant.insert(obj);
- }
- }
- show_set(variant);
- in.close();
- //_getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement