NurAliya

set 2

Jul 9th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <set>
  4. #include <vector>
  5. #include <string>
  6. #include <iterator>
  7. #include <algorithm>  
  8. using namespace std;
  9. ifstream in("input.txt");
  10. ofstream out("output.txt");
  11.  
  12. int main()
  13. {
  14.     string s;
  15.     vector <string> v, result;
  16.     multiset <char> set1, set2;
  17.     set <string> U;
  18.  
  19.     while (!in.eof())
  20.     {
  21.         getline(in, s);
  22.         v.push_back(s);
  23.     }
  24.  
  25.     for (int i = 0; i < v.size(); i++)
  26.     {
  27.         set <char> c1 = { '?' };
  28.         set <char> c2 = { '!' };
  29.         for (int j = 0; j < s.length(); j++)
  30.         {
  31.             if ((ispunct(s[j])) && (c1.count(s[j]) == 1))
  32.             {
  33.                 for (int k = 0; k < j; k++)
  34.                 {
  35.                     set1.insert(s[k]);
  36.                 }
  37.             }
  38.             if ((ispunct(s[j])) && (c2.count(s[j]) == 1))
  39.             {
  40.                 for (int h = 0; h < j; h++)
  41.                 {
  42.                     set2.insert(s[h]);
  43.                 }
  44.             }
  45.         }
  46.     }
  47.     set<string>::iterator it;
  48.     set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), inserter(U, U.begin()));
  49.     for (auto it : U)
  50.     {
  51.         out << it << endl;
  52.     }
  53.     return 0;
  54. }
Add Comment
Please, Sign In to add comment