include iostream include fstream include string using namespace std in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream infile("input.txt");
ofstream outFile("output.txt");
int totalCount = -1;
int maxDay = 0;
string lastName = "";
if (infile.is_open())
{
string tmpLastName = "";
int details[5];
while (infile >> tmpLastName >> details[0] >> details[1] >> details[2] >>
details[3] >> details[4])
{
int tmpTotalCount = 0;
int tmpMaxDay = 0;;
for (int i = 0; i < 5; i++){
tmpTotalCount += details[i];
if (details[i] > details[tmpMaxDay]){
tmpMaxDay = i;
}
}
if (tmpTotalCount > totalCount){
totalCount = tmpTotalCount;
lastName = tmpLastName;
maxDay = tmpMaxDay;
}
outFile << lastName << ", всего деталей: " << tmpTotalCount << "\n\r";
}
outFile << "Лучший: " << lastName << ", номер дня недели: " << maxDay + 1;
infile.close();
outFile.close();
}
else cout << "Unable to open file";
return 0;
}