awsmpshk

Очереди, Кузичкин 141 группа

May 21st, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. queue<string> stringDivide(string s)
  8. {
  9.   string str = "";
  10.   queue<string> que;
  11.   for (int i = 0; i < s.length(); ++i)
  12.   {
  13.     if (s[i] == " ") {
  14.       que.push(str);
  15.       str = "";
  16.       continue;
  17.     }
  18.     str += s[i];
  19.   }
  20.   return que;
  21. }
  22.  
  23. void printQueue(queue<string> que)
  24. {
  25.   for (string s : que) cout << s << " ";
  26. }
  27.  
  28. int main()
  29. {
  30.   string base;
  31.   getline(cin, base);
  32.   queue<string> que = stringDivide(base);
  33.   char ch = que.front()[0].toUpper();
  34.   que.pop();
  35.   queue<string> firstIsSame, firstIsNotSame;
  36.   int cnt = 0;
  37.   while (que.size() != 0)
  38.   {
  39.     if (que.front()[0].toUpper == ch)
  40.     {
  41.       cnt++;
  42.       firstIsSame.push(que.front());
  43.       que.pop();
  44.     }
  45.     else
  46.     {
  47.       firstIsNotSame.push(que.front());
  48.       que.pop();
  49.     }
  50.   }
  51.   printQueue(firstIsSame);
  52.   printQueue(firstIsNotSame);
  53.   cout << endl;
  54.   return 0;
  55. }
Add Comment
Please, Sign In to add comment