kokokozhina

14

Dec 9th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream> //exercise 14
  2. #include <string> //delete words which include all letters from the first word
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool includes(string first, string s)
  9. {
  10.     vector<char> a;
  11.     for(unsigned i = 0; i < first.length(); i++)
  12.         if (first[i] >= 'a' && first[i] <= 'z' || first[i] >= 'A' && first[i] <= 'Z' )
  13.             a.push_back(first[i]);
  14.     //for(unsigned j = 0; j < a.size(); j++)
  15.     //  cout << a[j] << " ";
  16.     //cout << endl;
  17.     vector<bool> incAll(a.size(), true);
  18.     for(unsigned i = 0; i < s.length(); i++)
  19.         for(unsigned j = 0; j < a.size(); j++)
  20.         {
  21.             if (a[j] == s[i])
  22.                 incAll[j] = false;
  23.         }
  24.     bool NOinclusion = false;
  25.     //for(unsigned j = 0; j < incAll.size(); j++)
  26.     //  cout << incAll[j] << " ";
  27.     //cout << endl;
  28.     for(unsigned j = 0; j < incAll.size(); j++)
  29.         NOinclusion += incAll[j];
  30.     //cout << NOinclusion << endl;
  31.     if (NOinclusion)
  32.         return false;
  33.     else
  34.         return true;
  35. }
  36.  
  37. int main()
  38. {
  39.         ifstream in("input.txt");
  40.         ofstream out("output.txt");
  41.  
  42.         string first;
  43.         string s;
  44.         bool firstWas = false;
  45.         bool firstNoErase = true;
  46.         while(in >> s)
  47.         {
  48.             if (!firstWas)
  49.             {
  50.                 firstWas = true;
  51.                 first = s;
  52.             }
  53.             if (!includes(first, s) || firstNoErase)
  54.                 out << s << " ";
  55.             firstNoErase = false;
  56.         }
  57.  
  58.         in.close();
  59.         out.close();
  60.         system("pause");
  61.         return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment