Sephinroth

page_74_default_queue

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