Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     ifstream file;
  9.     int n = 0, min = 0, max = 0, min_stop = 0, max_stop = 0, total = 0, in, out , current = 0;
  10.     file.open(argv[0]);
  11.  
  12.     if (file)
  13.     {
  14.         file >> n;
  15.     }
  16.     else
  17.     {
  18.         cout << " File not found" << endl; return 0;
  19.     }
  20.  
  21.     file >> in >> out;
  22.     current = in;
  23.     min = current;
  24.     max = current;
  25.     min_stop = 0;
  26.     max_stop = 0;
  27.     total = in;
  28.  
  29.  
  30.  
  31.     for (int i = 1; i < n; i++)
  32.     {
  33.         file >> in >> out;
  34.         current = current + in - out;
  35.         total += in;
  36.  
  37.  
  38.         if (current > max)
  39.         {
  40.             max = current;
  41.             max_stop = i;
  42.         }
  43.         else if (current < min)
  44.             {
  45.                 min = current;
  46.                 min_stop = i;
  47.             }
  48.     }
  49.  
  50.     file.close();
  51.  
  52.     cout << "total: " << total << endl;
  53.     cout << "min: " << min << " at " << min_stop << endl;
  54.     cout << "max: " << max << " at " << max_stop << endl;
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement