| ||||||||||
| 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<iostream>
using namespace std;
int x,y,flag,times;
int ret[3];
int chu[3]={23,28,33};
int function(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
else
{
int tmp;
function(b,a%b,x,y);
tmp=x;
x=y;
y=tmp-(a/b)*y;
return x*a;
}
}
void run()
{
int i,sum=0,d;
for(i=0;i<3;i++)
cin>>ret[i];
if(ret[0]==-1)
{
flag=0;
return;
}
cin>>d;
for(i=0;i<3;i++)
sum+=function(23*28*33/chu[i],chu[i],x,y)*ret[i];
while(sum<=d) sum+=23*28*33;
while(sum>d+23*28*33) sum-=23*28*33;
cout<<"Case "<<times<<": the next triple peak occurs in ";
cout<<sum-d;
cout<<" days."<<endl;
times++;
}
int main()
{
times=1;
flag=1;
while(flag)
run();
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator