fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5. int n;
  6. cin >> n;
  7. queue<ll> q;
  8. int x;
  9. int sum = 0.0;
  10. int i = 0;
  11. while(1){
  12. i++;
  13. cin >> x;
  14. if(x == - 1)
  15. break;
  16. sum = sum + x;
  17. if(i > n){
  18. sum = sum - q.front();
  19. q.pop();
  20. }
  21. q.push(x);
  22. ll d = min(i, n);
  23. cout << (double)(sum)/q.size() << " ";
  24. }
  25. cout << "\n";
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4368KB
stdin
5
51 62 24 51 79 33 72 78 84 42 -1
stdout
51 56.5 45.6667 47 53.4 49.8 51.8 62.6 69.2 61.8