Advertisement
hopingsteam

Untitled

Apr 25th, 2020
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include    <iostream>
  2. #include    <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("bac.txt");
  7.  
  8. int main()
  9. {
  10.     int s = 0, smin = 0, negat = 0;
  11.     int x, xmin = 1000;
  12.     while(fin >> x)
  13.     {
  14.         s = s + x;
  15.         if(s < smin)
  16.             smin = s;
  17.         if(s > 0)
  18.             s = 0;
  19.         if(x < 0)
  20.             negat++;
  21.         if(x < xmin)
  22.             xmin = x;
  23.     }
  24.     if(negat == 0)
  25.         cout << xmin;
  26.     else
  27.         cout << smin;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement