北大acm题库的1006题,怎么总是wrong answer啊?
我的程序是#include"stdio.h"#defineN10000voidmain(){intp[N],e[N],i[N],d[N],j=0,n=0,m[N];whi...
我的程序是
#include "stdio.h"
#define N 10000
void main()
{int p[N],e[N],i[N],d[N],j=0,n=0,m[N];
while(1)
{scanf("%d%d%d%d",&p[j],&e[j],&i[j],&d[j]);
j++;
if(p[j-1]==-1&&e[j-1]==-1&&i[j-1]==-1&&d[j-1]==-1)
break;
n++;
}
for(j=0;j<n;j++)
{m[j]=d[j];
while(1)
{
if(((m[j]-p[j])%23)==0&&((m[j]-e[j])%28)==0&&((m[j]-i[j])%33)==0)
break;
m[j]++;
}
}
for(j=0;j<n;j++)
printf("Case %d: the next triple peak occurs in %d days.\n",j+1,m[j]-d[j]);
} 展开
#include "stdio.h"
#define N 10000
void main()
{int p[N],e[N],i[N],d[N],j=0,n=0,m[N];
while(1)
{scanf("%d%d%d%d",&p[j],&e[j],&i[j],&d[j]);
j++;
if(p[j-1]==-1&&e[j-1]==-1&&i[j-1]==-1&&d[j-1]==-1)
break;
n++;
}
for(j=0;j<n;j++)
{m[j]=d[j];
while(1)
{
if(((m[j]-p[j])%23)==0&&((m[j]-e[j])%28)==0&&((m[j]-i[j])%33)==0)
break;
m[j]++;
}
}
for(j=0;j<n;j++)
printf("Case %d: the next triple peak occurs in %d days.\n",j+1,m[j]-d[j]);
} 展开
2个回答
展开全部
我的程序:
#include<stdio.h>
int fPE(int p,int e)
{
int i=p;
while(i<e)
i+=23;
while((i-e)%28!=0)
i+=23;
return i;
}
int fPEI(int pe,int i)
{
int s=pe;
while(s<i)
s+=644;
while((s-i)%33!=0)
s+=644;
return s;
}
int fD(int pei,int d)
{
while(pei<=d)
pei+=21252;
while(pei-d>21252)
pei-=21252;
return(pei-d);
}
main()
{
int p,e,i,d,pe,pei,res,num=1;
scanf("%d %d %d %d",&p,&e,&i,&d);
while(p!=-1)
{
pe=fPE(p,e);
pei=fPEI(pe,i);
res=fD(pei,d);
printf("Case %d: the next triple peak occurs in %d days.\n",num,res);
num++;
scanf("%d %d %d %d",&p,&e,&i,&d);
}
return 0;
}
#include<stdio.h>
int fPE(int p,int e)
{
int i=p;
while(i<e)
i+=23;
while((i-e)%28!=0)
i+=23;
return i;
}
int fPEI(int pe,int i)
{
int s=pe;
while(s<i)
s+=644;
while((s-i)%33!=0)
s+=644;
return s;
}
int fD(int pei,int d)
{
while(pei<=d)
pei+=21252;
while(pei-d>21252)
pei-=21252;
return(pei-d);
}
main()
{
int p,e,i,d,pe,pei,res,num=1;
scanf("%d %d %d %d",&p,&e,&i,&d);
while(p!=-1)
{
pe=fPE(p,e);
pei=fPEI(pe,i);
res=fD(pei,d);
printf("Case %d: the next triple peak occurs in %d days.\n",num,res);
num++;
scanf("%d %d %d %d",&p,&e,&i,&d);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询