http://acm.pku.edu.cn/JudgeOnline/problem?id=1006
此题属于枚举题、
代码如下:
#include <stdio.h>
int main()
{
int p,e,i,d,n = 0,k;
scanf("%d%d%d%d",&p,&e,&i,&d);
while(p != -1 && e != -1 && i != -1 && d != -1)
{
n ++;
p = p % 23;
e = e % 28;
i = i % 33;
for(k = d + 1;;k++)
{
if(((k - p) % 23) == 0 && ((k - e) % 28) == 0 && ((k - i) % 33) == 0)
{ printf("Case %d: the next triple peak occurs in %d days./n",n,k - d);
break;}
}
scanf("%d%d%d%d",&p,&e,&i,&d);
}
return (0);
}
/*
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.
*/