Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main(int argc, char** argv)
- {
- ifstream file;
- int n = 0, min = 0, max = 0, min_stop = 0, max_stop = 0, total = 0, in, out , current = 0;
- file.open(argv[0]);
- if (file)
- {
- file >> n;
- }
- else
- {
- cout << " File not found" << endl; return 0;
- }
- file >> in >> out;
- current = in;
- min = current;
- max = current;
- min_stop = 0;
- max_stop = 0;
- total = in;
- for (int i = 1; i < n; i++)
- {
- file >> in >> out;
- current = current + in - out;
- total += in;
- if (current > max)
- {
- max = current;
- max_stop = i;
- }
- else if (current < min)
- {
- min = current;
- min_stop = i;
- }
- }
- file.close();
- cout << "total: " << total << endl;
- cout << "min: " << min << " at " << min_stop << endl;
- cout << "max: " << max << " at " << max_stop << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement