Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <algorithm>
  8. #include <iterator>
  9. #include <conio.h>
  10. #include <stack>
  11. #include <set>
  12.  
  13. using namespace std;
  14.  
  15. void show_set(const set <string>& A)
  16. {
  17.  
  18.     copy(A.begin(), A.end(), ostream_iterator<string>(cout, " "));
  19.     cout << endl;
  20. }
  21.  
  22. bool isStrDigit(const string& str)
  23. {
  24.     int ret = 0;
  25.     if ((str[0] == '-') || (str[0] == '+'))
  26.         ret++;
  27.    
  28.     for (int i = ret; i < str.size(); i++)
  29.         if (!isdigit(str[i]))
  30.         {
  31.             return 0;
  32.         }
  33.     return 1;
  34. }
  35.  
  36. string convertToString(int i)
  37. {
  38.     string res;
  39.     res.clear();
  40.     stack <char> digit;
  41.  
  42.     if (i < 0)
  43.         digit.push('-');
  44.     else
  45.         if (i == 0)
  46.         {
  47.             res = '0';
  48.             return res;
  49.         }
  50.  
  51.     i = abs(i);
  52.  
  53.     while (i > 0)
  54.     {
  55.         digit.push(i % 10 + 48);
  56.         i = i / 10;
  57.     }
  58.  
  59.     while (!digit.empty())
  60.     {
  61.         res += digit.top();
  62.         digit.pop();
  63.     }
  64.     return res;
  65. }
  66.  
  67. int main()
  68. {
  69.     ifstream in("input.txt");
  70.     vector <string> chest;
  71.     set <string> variant;
  72.     multimap <string, int> podch;
  73.     string obj, obj2;
  74.  
  75.  
  76.     while (in >> obj)
  77.     {
  78.         chest.push_back(obj);
  79.     }
  80.  
  81.     for (int i = 0; i < chest.size(); i++)
  82.     {
  83.         if (isStrDigit(chest[i]))
  84.         {
  85.             podch.insert(pair <string, int>(chest[i], i));
  86.         }
  87.     }
  88.  
  89.     obj.clear();
  90.     obj2.clear();
  91.  
  92.     for (int i = 0; i < chest.size(); i++)
  93.     {
  94.         auto iterPair = podch.equal_range(chest[i]);
  95.         if (iterPair.first != iterPair.second)
  96.         {
  97.             //cout << "( " << chest[i] << ':';
  98.             obj = '(' + chest[i] + ':';
  99.  
  100.             for (auto nearIt = iterPair.first; nearIt != iterPair.second; ++nearIt)
  101.             {
  102.                 //cout << nearIt->second << ' ';
  103.                 obj += convertToString(nearIt->second) + ',';
  104.             }
  105.             //cout << ") ";
  106.             obj += ')';
  107.             obj.erase(obj.size() - 2, 1);
  108.             variant.insert(obj);
  109.         }
  110.     }
  111.  
  112.     show_set(variant);
  113.  
  114.     in.close();
  115.     //_getch();
  116.     return 0;
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement