Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 142163 | Accepted: 45711 |
Description
Input
Output
Sample Input
0 0 0 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 301 203 40 -1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days. Case 2: the next triple peak occurs in 21152 days. Case 3: the next triple peak occurs in 19575 days. Case 4: the next triple peak occurs in 16994 days. Case 5: the next triple peak occurs in 8910 days. Case 6: the next triple peak occurs in 10789 days.
本题采用基本数据类型int即可
#include
#include
using namespace std;
int p = 0, e = 0, i = 0, d = 0;
int calculate();
void stdOut(int num, int days);
int main()
{
int days = 0, num = 1;
while (cin >> p >> e >> i >> d) {
if ((p == -1) && (e == -1) && (i == -1) && (d == -1)) {
break;
}
days = calculate();
stdOut(num, days-d);
num++;
}
return 0;
}
int calculate()
{
int num = 0;
for (num = d+1; num < 21252-d; num++) {
if (((num-p)%23 == 0) && ((num-e)%28 == 0) && ((num-i)%33 == 0) ) {
break;
}
}
return num ;
}
void stdOut(int num, int days)
{
cout << "Case " << num << ": the next triple peak occurs in " << days << " days." << endl;
}
高级版
#include
int main()
{
int p,e,i,d,k=1,a;
while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
{
if(p==-1&&e==-1&&i==-1&&d==-1)break;
a=((5544*p+14421*e+1288*i)-d)%21252;
if(a<=0)a+=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",k++,a);
}
return 0;
}