POJ 1006.Biorhythms

水题,注意在一开始日期的遍历要从给的第四个输入开始,一开始因为这个WA了不少次

题目链接

代码:

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <cmath>
#include <cstdlib>
//23 28 33
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char** argv) {
	
	int jishu = 1;
	
	
	while(1)
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a==-1&&b==-1&&c==-1&&d==-1)
		return 0;
//	int count = 0;
//	int minnumber = a;
//	if(b<minnumber)
//	{
//		minnumber= b;
//	}
//	if(c<minnumber)
//	{
//		minnumber = c;
//	}
	for(int i=d+1;;i++)//这里的i为什么要从d开始 因为至少在这一天后边 
	{
		if((i-a)%23==0&&(i-b)%28==0&&(i-c)%33==0)
		{
		if((i-d)!=21252) 
			printf("Case %d: the next triple peak occurs in %d days.\n",jishu,(i-d)%21252);
		else
			printf("Case %d: the next triple peak occurs in %d days.\n",jishu,21252);
			jishu++;
			break;
		}
	}
}
	//i最终的输出值是一个天数,所以这个i的值肯定要大于d 
	//system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/curiousliu/article/details/80107688