-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem9.cpp
More file actions
52 lines (46 loc) · 1006 Bytes
/
Copy pathproblem9.cpp
File metadata and controls
52 lines (46 loc) · 1006 Bytes
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
44
45
46
47
48
49
50
51
52
#include "iostream"
#include "fstream"
inline unsigned int myatoi(const char digit)
{
switch(digit)
{
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
}
}
unsigned int mult(const char* digits)
{
return (myatoi(digits[0]) * myatoi(digits[1]) * myatoi(digits[2]) *
myatoi(digits[3]) * myatoi(digits[4]));
}
int main(int argc, char** argv)
{
unsigned int max_mult = 0;
unsigned int i = 0;
char* digits = new char[6];
std::fstream file;
file.open("./number.txt");
if(file.is_open())
{
while(i < 1000)
{
file.seekp(i);
//std::cout<<digits<<std::endl;
file.get(digits, 6, '\n');
max_mult = std::max(max_mult, mult(digits));
++i;
}
}
file.close();
delete[] digits;
std::cout << max_mult<<std::endl;;
return 0;
}