Sephinroth

page_74_default_list

May 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. /*4. Ñîçäàòü  ñïèñîê  èç  ñëîâ.  Ïîäñ÷èòàòü,  ñêîëüêî  ñëîâ  íà÷èíàåòñÿ
  2. íà  äàííóþ  áóêâó.
  3. Ñîçäàòü èç íèõ íîâûé ñïèñîê, óäàëèâ èõ èç èñõîäíîãî ñïèñêà.*/
  4.  
  5. #include <fstream>
  6. #include <string>
  7. #include <list>
  8. using namespace std;
  9. int main(){
  10.     list<string> l1;
  11.     list<string> l2;
  12.     string str, a;
  13.     int cnt = 0;
  14.     ifstream in ("input.txt");
  15.     ofstream out ("output.txt");
  16.     in >> a;
  17.     while (in >> str){
  18.         l1.push_back(str);
  19.         if (str.find_first_of(a) < string::npos) cnt++;  }
  20.     in.close();
  21.     while (!l1.empty()){
  22.         string q = l1.front();
  23.         if (q.find_first_of(a) != string::npos){ l1.pop_front(); continue;} else l2.push_back(q);
  24.         l1.pop_front();
  25.     }
  26.     while (!l2.empty()){
  27.         out << l2.front() << ' ';
  28.         l2.pop_front();}
  29.     out << '\n' << "Count = " << cnt << endl;  
  30.     out.close();
  31.     return 0;              
  32. }
Add Comment
Please, Sign In to add comment