Moderator: Board moderators
#include <stdio.h>
#define MAX 21300
char days[MAX];
int main(void)
{
int i,n,N,P,E,I,d,c;
scanf("%d",&N);
for(n=0;n<N;n++)
{
c = 1;
while(scanf("%d %d %d %d",&P,&E,&I,&d) == 4)
{
if((P == -1) && (E == -1) && (I == -1) && (d == -1)) break;
for(i=0;i<MAX;i++) days[i] = 0;
for(i=P;i<MAX;i+=23) days[i]++;
for(i=P-23;i>0;i-=23) days[i]++;
for(i=E;i<MAX;i+=28) days[i]++;
for(i=E-28;i>0;i-=28) days[i]++;
for(i=I;i<MAX;i+=33) days[i]++;
for(i=I-33;i>0;i-=33) days[i]++;
for(i=d+1;i<MAX;i++) if(days[i] == 3) break;
if(i > 21252) i = d + 21252;
printf("Case %d: the next triple peak occurs in %d days.\n",
c++,i-d);
}
if(n < N-1) printf("\n");
}
return 0;
}
#include<iostream.h>
main()
{
int p,e,i,d,z,count=1,cases;
for(cin >> cases;cases--;){
while(1)
{
cin>>p>>e>>i>>d;
if(p==-1) break;
p = p % 23;
e = e % 28;
i = i % 33;
z = (d/33*33)+i;
if(z==d) z+=33;
for(;z<=21252;z+=33)
if (z%23==p && z%28==e) break;
cout<<"Case "<<count<<": the next triple peak occurs in "
<<(z-d)<<" days.\n";
count++;
}count=1;cout << "\n";
}
}
you may assume that a triple peak will occur within 21252 days of the given date.
WR wrote:The program reproduces all output as it should be, following the posts.
Nevertheless I still get WA.

Dominik Michniewski wrote:Could anyone tell me what's wrong with this algorithm ?
- Code: Select all
#include <stdio.h>
#define MAX 21300
Dominik Michniewski wrote:
- Code: Select all
if(i > 21252) i = d + 21252;
printf("Case %d: the next triple peak occurs in %d days.\n",
c++,i-d);
I don't talk about eficiency of this algorithm, because it's poorbut about cases in which these code doesn't work ... I can't find such one ....
Please help!!!
Dominik Michniewski
if(i>21252)if(i>d+21252)szymcio2001 wrote:WR wrote:The program reproduces all output as it should be, following the posts.
Nevertheless I still get WA.
It's a multiple input problem.
WR wrote:szymcio2001 wrote:It's a multiple input problem.
Multiple input means there's more than input line? The program
should handle that. Or is there a misconception of multiple input
on my side?!
Users browsing this forum: No registered users and 1 guest