Advertisement
Infiniti_Inter

5.11 №1 (stack) (Olya)

Jan 21st, 2020
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. #include <string>
  5. #include <stack>
  6. using namespace std;
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.  
  15.     stack<int> s;
  16.     int cnt, sum;
  17.     cnt = sum = 0;
  18.     while (in.peek() != EOF)
  19.     {
  20.         int cur; in >> cur;
  21.         if (cur % 2 == 0)
  22.         {
  23.             s.push(cur);
  24.             cnt++;
  25.             sum += cur;
  26.         }
  27.     }
  28.     out << "AVG : " << 1.*sum / cnt << endl;
  29.     while (!s.empty())
  30.     {
  31.         int cur = s.top(); s.pop();
  32.         out << cur << " ";
  33.     }
  34.     //
  35.     //  12 54 3 51 8 4 3 84 2 42 3 4 5 2
  36.     //
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement