Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- ifstream file;
- file.open("..\\tess.txt");
- //error checking
- if (!file.is_open()) {
- cout << "ERROR\n\n";
- return 1;
- }
- string str; //читаю строку
- int k = 0;
- int rez = NULL; //результат
- int old_sum = 0;
- while (getline(file, str)) {
- str += " ";
- string::size_type sz = 0;
- int sum = 0;
- int index = 0;
- while (sz < str.length()) {
- int i_dec = stoi(str, &sz);
- sum += i_dec;
- str = str.substr(sz + 1);
- index++;
- }
- cout << "In:" << k << "\tsum: " << sum << endl;
- cout << "\n";
- if (k == 0) {
- old_sum = sum;
- rez = k;
- } else if (old_sum > sum) {
- old_sum = sum;
- rez = k;
- }
- k++;
- sum = 0;
- }
- cout << "REZ: " << rez << endl << endl;
- file.close();
- ifstream fileNew;
- file.open("..\\tess.txt");
- //error checking
- if (!file.is_open()) {
- cout << "ERROR\n\n";
- return 1;
- }
- k = 0;
- while (getline(file, str)) {
- if (k == rez) {
- cout << str;
- break;
- }
- k++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment