| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我用周期取整方法做的就是算出满足日期一致的条件下三个周期的个数同时为整数时的最早日期,再同当前日期进行对比处理得出答案。
#include<stdio.h>
int main()
{
float a,b,c,x,y,z;
int days,data,ty,tz,i=0;
while(true)
{
scanf("%f%f%f%d",&a,&b,&c,&data);
if(a==-1&&b==-1&&c==-1&&data==-1)break;
i++;
a=int(a)%23;b=int(b)%28;c=int(c)%33;
for(x=0.0;;x++)
{
y=(a-b+23*x)/28;
z=(a-c+23*x)/33;
ty=int(y);
tz=int(z);
y-=ty;
z-=tz;
if(y==0.0&&z==0.0)break;
}
if(a+23*x-data<0)
days=int(a+23*x+21252-data);
else if(a+23*x-data>0)
days=int(a+23*x-data);
else
days=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",i,days);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator