Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A

Posted by KatrineYang at 2016-09-25 05:19:56 on Problem 1367 and last updated at 2016-09-25 05:20:01
#include <iostream>
#include <stdio.h>
using namespace std;

struct dt{
	int year, month, day, hour, minute, second;
}ks, js;

int partial_month_day[12] = {0,31,59,90,120,151,181,212,243,273,304,334};

int gs;
char type[10];

int mx(int a, int b){
	return (a>b) ? a : b;
}

int days(dt &d){
	int jben = (d.year-1970)*365+partial_month_day[d.month-1]+d.day+(d.year-1969)/4;
	if(d.year%4==0 && d.month>=3) jben++;
	return jben;
}

int main() {
	while(scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &ks.year, &ks.month, &ks.day, &ks.hour, &ks.minute, &ks.second, &js.year, &js.month, &js.day, &js.hour, &js.minute, &js.second) == 12){
		scanf("%d%s", &gs, type);
		//cout << type[0] << type[1] << endl;
		switch(type[0]+type[1]){
			case 'y'+'e':{
				if(!(ks.month==1&&ks.day==1&&ks.hour==0&&ks.minute==0&&ks.second==0)) ks.year++;
				printf("%d\n", (mx(0,js.year-ks.year))/gs);
				break;
			}
			case 'm'+'o':{
				int zys = (js.year-ks.year)*12+js.month-ks.month;
				if(!(ks.day==1&&ks.hour==0&&ks.minute==0&&ks.second==0)) zys--;
				printf("%d\n", (mx(0,zys)/gs));
				break;
			}
			case 'd'+'a':{
				int zrs = days(js)-days(ks);
				if(ks.hour|ks.minute|ks.second) zrs--;
				printf("%d\n", (mx(0,zrs)/gs));
				break;
			}
			case 'h'+'o':{
				int zxss = (days(js)-days(ks))*24+js.hour-ks.hour;
				if(ks.minute|ks.second) zxss--;
				printf("%d\n", (mx(0,zxss)/gs));
				break;
			}
			case 'm'+'i':{
				//cout << "*" << days(js)-days(ks) << endl;
				//cout << js.hour << " " << ks.hour << endl;
				int zfzs = (days(js)-days(ks))*24*60+(js.hour-ks.hour)*60+(js.minute-ks.minute);
				//cout << "#" << zfzs << endl;
				if(ks.second) zfzs--;
				printf("%d\n", (mx(0,zfzs)/gs));
				break;
			}
			case 's'+'e':{
				int zms = (days(js)-days(ks))*24*3600+(js.hour-ks.hour)*3600+(js.minute-ks.minute)*60+js.second-ks.second;
				printf("%d\n", zms/gs);
				break;
			}
			default:break;
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator