Advertisement
Infiniti_Inter

1, 3 (Olya) List

Jan 8th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <algorithm>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9.  
  10.  
  11. int main()
  12. {
  13.  
  14.     list<int> l;
  15.     list<int> even_l;
  16.     int cnt = 0;
  17.     long long sum = 0;
  18.     while (in.peek() != EOF)
  19.     {
  20.         int cur; in >> cur;
  21.         l.push_back(cur);
  22.     }
  23.  
  24.     while (!l.empty())
  25.     {
  26.         int cur = l.front();
  27.         l.pop_front();
  28.         if (cur % 2 == 0)
  29.         {
  30.             cnt++;
  31.             sum += cur;
  32.             even_l.push_back(cur);
  33.         }
  34.     }
  35.     out << "count of even : " << cnt << "\n";
  36.     out << "sum of even : " << sum << "\n";
  37.     out << "AVG : " << sum * 1.0 / cnt;
  38.     //even_l - лист с четными числами
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement