这次程序,竟然写了一个多小时。!
只因为忽略了两句话:
【所有给定时间是非负的并且小于365, 所求的时间小于21252。】
细节不是骗局,忽略细节才是骗局!
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int count,j;
count=0;
int p,e,i,d;
int t;
while(cin>>p>>e>>i>>d)
{
if(p==-1&&e==-1&&i==-1&&d==-1)return 0;
if(p==e&&e==i)
{
p+=23;
e+=28;
i+=33;
}
while(p!=e||e!=i||p!=i)
{
if(p<e||p<i)p+=23;
if(e<i||e<p)e+=28;
if(i<p||i<e)i+=33;
}
int tmp=i-d;
if(tmp>21252)tmp=tmp%21252;
if(tmp<0)tmp+=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",++count,tmp);
}
return 0;
}
这个代码的运行速度较慢,以后有时间会改进!