Advertisement
Infiniti_Inter

1(Alisa)

Dec 19th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. ifstream in("input.txt");
  11. ofstream out("output.txt");
  12.  
  13.  
  14.  
  15.  
  16. int main()
  17. {
  18.     int n;
  19.     in >> n;
  20.     string trash;//очистка буффера перед getline(иначе считается лишний пробел)
  21.     getline(in, trash);
  22.     queue<string> q;
  23.     size_t maxSize = 0;
  24.     for (int i = 0; i < n; ++i)
  25.     {
  26.         string s;
  27.         getline(in, s);
  28.         q.push(s);
  29.         maxSize = max(maxSize, s.length());
  30.     }
  31.     queue<string> reverse_q;
  32.     //создаем вспомогательную очередь, которая будет хранить
  33.         //элементы, но в обратном порядке
  34.     while (!q.empty())
  35.     {
  36.         string cur = q.front(); q.pop();
  37.         if (cur.length() == maxSize)
  38.             out << cur << endl;
  39.         else
  40.             reverse_q.push(cur);
  41.     }
  42.     while (!reverse_q.empty())//перевернем очередь, чтобы получить прямой порядок
  43.     {
  44.         string cur = reverse_q.front(); reverse_q.pop();
  45.         q.push(cur);
  46.     }
  47.     while (!q.empty())
  48.     {
  49.         string cur = q.front(); q.pop();
  50.         out << cur << endl;
  51.     }
  52. /*
  53. пример входных данных
  54. 5
  55. Mario Beane 4 3 2
  56. Bavera Eldred 1 2 3
  57. Ahirlene Bode 3 2 1
  58. Neoma Boggs 3 2 1
  59. Cong Heston 5 5 5
  60.  
  61. */
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement