forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP8.cpp
More file actions
43 lines (43 loc) · 1.01 KB
/
P8.cpp
File metadata and controls
43 lines (43 loc) · 1.01 KB
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<cstdio>
using namespace std;
int a[14];//记录13个位置的数字
int main()
{
int t = 0, temp, s = 1;//t代表已经记录的位置数,s代表即将被更改的位置
bool flag = false;
long long sum = 0LL, now = 1LL;
int cnt = 0;
while(++cnt <= 1000)
{
scanf("%1d", &temp);//只读一个数字
if(0 == temp)
{
t = 0;
s = 1;
flag = false;
continue;
}
if(t < 13)
a[++t] = temp;
else if(flag)
{
now = now / a[s] * temp;
if(now > sum)
sum = now;
a[s] = temp;
s = s % 13 + 1;
}
if(13 == t && !flag)
{
now = 1LL;
for(int k = 1; k <= 13; k++)
now *= a[k];
if(now > sum)
sum = now;
flag = true;
}
}
printf("%I64d\n", sum);
return 0;
}