Advertisement
Sephinroth

page_74_default_stack

May 21st, 2019
141
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 <stack>
  8. using namespace std;
  9. int main(){
  10.     stack<string> s1;
  11.     stack<string> s2;
  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.         s1.push(str);
  19.         if (str.find_first_of(a) < string::npos) cnt++;  }
  20.     in.close();
  21.     while (!s1.empty()){
  22.         string q = s1.top();
  23.         if (q.find_first_of(a) != string::npos){ s1.pop(); continue;} else s2.push(q);
  24.         s1.pop();
  25.     }
  26.     while (!s2.empty()){
  27.         out << s2.top() << ' ';
  28.         s2.pop();}
  29.     out << '\n' << "Count = " << cnt << endl;  
  30.     out.close();
  31.     return 0;              
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement