The condition of the problem is such that the sum of the two first numbers can be equal to slightly less than 2 * (10 ^ 9), i.e. It takes about 2 GB, and this is more than the limit of 16 MB !!! How to get around? Help solve.
Input file name in.txt Output file name standard output Memory limit 16 megabytes
The beginning of the in.txt file contains two integers. If you add them, then you get the position in the file, starting with which is the third number that you need to display.
Input Format The file in.txt , formed according to the principle described above. It is guaranteed that each of the numbers is integer and does not exceed 10 ^ 9. It is also guaranteed that the sum of the first two numbers will not be a negative number.
Examples
Input data:
6 5 blah 25491
Output:
491
Problem solved, thanks Harry, here is the correct code:
#include <iostream> #include <fstream> using namespace std; int main(){ ifstream infile; infile.open("in.txt", ios::in); int a, b, j = 0, pos1; //вывел два первых числа и сложил их infile >> a >> b; j = a+b; // потом, как Вы и сказали сдвинул infile.seekg(j, ios:: beg); infile >> pos1; cout << pos1; infile.close(); return 0; }