[c] #include <stdio.h>
#include <fcntl.h>
int main(void)
{
char in[10];
int cas=1,x,t;
#ifndef ONLINE_JUDGE
close (0); open ("756.in", O_RDONLY);
close (1); open ("756.out", O_WRONLY | O_CREAT, 0600);
#endif
scanf("%d",&cas);
for(x=0;x<cas;x++)
{
gets(in);
t=0;
while(1)
{
long int n,p,e,i,d;
n=0;
scanf("%d %d %d %d",&p,&e,&i,&d);
if(p==-1 &&e==-1 && i==-1 && d==-1)
break;
t++;
n=p>e?p:e;
n=i>n?i:n;
n++;
while(1)
{
if((n-p)%23==0 && (n-e)%28==0 && (n-i)%33==0)
break;
n++;
}
printf("Case %d: the next triple peak occurs in %d days.\n",t,n-d);
}
printf("\n");
}
}
[/c]
Can anyone tell me why this is giving WA?
For this input:
Code: Select all
4
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
210 44 270 348
152 37 4 148
365 290 231 89
-1 -1 -1 -1
365 365 365 365
364 364 364 364
363 363 363 363
1 1 1 1
-1 -1 -1 -1
0 10 1 0
353 361 0 100
-1 -1 -1 -1
I get this output:
Code: Select all
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.
Case 1: the next triple peak occurs in 20976 days.
Case 2: the next triple peak occurs in 21141 days.
Case 3: the next triple peak occurs in 21229 days.
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21252 days.
Case 3: the next triple peak occurs in 21252 days.
Case 4: the next triple peak occurs in 21252 days.
Case 1: the next triple peak occurs in 17986 days.
Case 2: the next triple peak occurs in 989 days.
My approach is brute force, but it definitely works quite fast... Is there some input for which this would fail? or is it a problem with the formatting?