fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4.  
  5. struct vector_t: public std::vector<int> {
  6. int& operator [] (unsigned int i){
  7. if( this->size() <= i ){ this->resize(i+1); }
  8. return this->at(i);
  9. }
  10. };
  11.  
  12.  
  13. int main(){
  14. using namespace std;
  15. vector_t t;
  16. int cnt, ten, i;
  17. double sum, avg;
  18.  
  19. cnt = 0;
  20. cin >> ten;
  21.  
  22. label_1:
  23. if( ten != 999 ){
  24. t[cnt] = ten;
  25. cnt = cnt + 1;
  26. cin >> ten;
  27. goto label_1;
  28. }
  29. sum = 0;
  30. i = 0;
  31.  
  32. label_2:
  33. if( i < cnt ){
  34. sum = sum + t[i];
  35. i = i + 1;
  36. goto label_2;
  37. }
  38. avg = sum / cnt;
  39.  
  40. cout << avg << endl;
  41.  
  42. exit(0);
  43. }
Success #stdin #stdout 0s 3300KB
stdin
999
stdout
-nan