Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <sstream>
  8. #include <math.h>
  9. #include <iomanip>
  10.  
  11. using namespace std;
  12.  
  13. int main() {
  14.     string cons;
  15.     string input;
  16.     stringstream ss;
  17.     double value;
  18.     bool strict = false;
  19.     bool integers_only = false;
  20.     int count = 0;
  21.  
  22.     vector<double> numbers;
  23.  
  24.     while(getline(cin, input) && input != "END") {
  25.         if(count == 0) {
  26.             if(input.find("strict") >= 0 && input.find("strict") <= 50) {
  27.                 strict = true;
  28.             }else if(input.find("integers-only") >= 0 && input.find("integers-only") <= 50) {
  29.                 integers_only = true;
  30.             }else if(input.find("strict:integers-only") >= 0 && input.find("strict:integers-only") <= 50) {
  31.                 strict = true;
  32.                 integers_only = true;
  33.             }
  34.         }      
  35.    
  36.    
  37.         ss << input;
  38.  
  39.         while(!ss.eof()) {
  40.             if(ss >> value) {
  41.                 numbers.push_back(value);
  42.                 count++;
  43.             }else if(ss.fail()) {
  44.                 ss.clear();
  45.                 string fail;
  46.                 ss >> fail;
  47.                 continue;
  48.             }
  49.         }
  50.  
  51.         ss.str(string());
  52.         ss.clear();
  53.     }
  54.  
  55.     double min = numbers[0];
  56.     double max = numbers[0];
  57.     double sum;
  58.     double average;
  59.     int counter = 0;
  60.  
  61.     for (auto i = numbers.begin(); i != numbers.end(); ++i) {
  62.  
  63.         if(*i > max) {
  64.             max = *i;
  65.         }
  66.  
  67.         if(*i < min) {
  68.             min = *i;
  69.         }
  70.  
  71.         sum += *i;
  72.        
  73.         counter++;
  74.     }
  75.  
  76.     average = sum / counter;
  77.     double rounded_avr = roundf(average * 100) / 100;
  78.  
  79.     cout << min << ' ';
  80.     cout << max << ' ';
  81.     cout << setprecision(4) << average << endl;
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement