H
H
Hikmatullo Azizov2021-11-02 03:44:31
C++ / C#
Hikmatullo Azizov, 2021-11-02 03:44:31

How to implement this task in c++?

Hello.
The task is this: there is an input.txt file in which the data of some kind of match is entered into two columns. It is required to read these data and find out which group won. For example, name the first group A, and the second B. Then save the result in the output.txt file.
Example,
Input.txt
3 4
5 2
1 2
Output.txt
AB
9 8

PS: Is it possible to implement this task using the fstream library?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Ushakov, 2021-11-02
@Nightmare1

Read the file line by line, divide the incoming line into two variables, respectively convert them to an integer. When running sum up, display the result of the sum sorted by the comparison condition. Do you need a code?

W
Wataru, 2021-11-02
@wataru

ifstream can read numbers. You need to read 2 numbers in a loop until the file ends. Checking that the file is over - through eof .
To solve your problem, in addition to the two readable variables, you will need to create two more counters - the sum of points for each command. Further, in the loop, after reading two numbers, just add them to the counters. After the loop, when eof is encountered, output counters. That's all the solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question