Holiday date string processing -9

Casual working:

 There are calendar  solar calendar (Gregorian calendar)  and the  lunar calendar (lunar calendar)  of the points. Every year holidays, which fall into three categories - day weekend, holiday Gregorian, lunar holidays.

  1. Day weekend

    1) Saturday and Sunday 2 days

  2. Gregorian holidays

    1) New Year's Day: Gregorian calendar year January 1, a holiday one day

    2) Labor Day: May 1 each year solar calendar, a holiday one day

    3) National Day: Gregorian calendar each year on October 1st, 3 days holiday

    4) Christmas: Gregorian calendar each year on December 25, one day holiday

  3. Lunar Holidays

    1) Chinese New Year: January 1st lunar year, 3 days holiday

    2) Ching Ming Festival: April 4 solar calendar every year - between the 6th day, a holiday one day

    3) Dragon Boat Festival: lunar calendar every year on May 5, one day holiday

    4) Mid-Autumn Festival: lunar calendar every year on August 15, one day holiday

 When the holidays and weekend coincides weekend not delayed nor in advance to ensure that no overlap between the holidays. Now to give you a year of all lunar holidays Gregorian date, and year of January 1 of the week, you calculate this year (Gregorian calendar on January 1st to December 31st) put the number of days off (including weekend, holidays and lunar solar calendar holidays).

Input Format

The first line of input year y (1900 <y≤2050).

Next four lines of the input two integers, m, d, respectively Spring Gregorian dates, festival, Dragon Boat Festival and the Mid.

The last line represents an integer year is January 1 (the first few days of the week, every week from Monday to start counting, that Monday is the first day) of the week.

Output Format

Output An integer representing the number of days of holiday that year.

Sample input

2017
1 28
4 4
5 30
10 4
7

Sample Output

113

 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;
const int maxn=10010;
const int N=10;

int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int mm[10]={1,5,10,10,10,12};
int dd[10]={1,1,1,2,3,25};
	
bool isleap(int y)	 { return (y%400==0)||(y%100!=0&&y%4==0);}
		
void nextday(int &m,int &d,int &w){
	
	d++;
	if(d==day[m]+1){
		d=1; m++;
	}
	
	w++; if(w==8) w=1;
}
		
int main(){
	
	int y,w;
	cin>>y;  if(isleap(y)) day[2]++;
	
	for(int i=6;i<10;i++)
	 cin>>mm[i]>>dd[i];

	cin>>w;
	
	int ans=0,f=0;
	int m=1,d=1;
	while(m<13){
		
		if(m==mm[6]&&d==dd[6]){
			ans++;
			f=2;
		}
		else if(f) { ans++; f--; }
		else if(w==6||w==7) ans++;
		else {
			
			for(int i=0;i<10;i++)
			 if(m==mm[i]&&d==dd[i]) ans++;
		}
		
		nextday(m,d,w);
	}
	
	printf("%d\n",ans);
	
	return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;
const int maxn=10010;
const int N=10;

int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int mm[12]={1,5,10,10,10,12} ;
int dd[12]={1,1,1,2,3,25} ; 

bool isleap(int y) { return (y%400==0)||(y%100!=0&&y%4==0);   }   

void nextday(int &m,int &d,int &w){
	
	d++;
	if(d==day[m]+1){
		m++; d=1;
	}
	
	w++;
	if(w==8) w=1;
}

void springfestival(int a,int b){
	
	mm[9]=a,dd[9]=b;
	
	b++; 
	if(b==day[a]+1) {  a++; b=1;  }	
	mm[10]=a; dd[10]=b;
	
	b++; 
	if(b==day[a]+1) {  a++; b=1;  }	
	mm[11]=a; dd[11]=b;
}

int main(){
	
	int a,b;
	int y,w;
	
	cin>>y;   if(isleap(y)) day[2]++;
	cin>>a>>b;
	
	for(int i=6;i<=8;i++)
	 cin>>mm[i]>>dd[i];
	
	cin>>w;
	//
	springfestival(a,b);
	//
	int ans=0;	
	int m=1,d=1;
	while(m<13){
		
		if(w==6||w==7) ans++;
		else {
			for(int i=0;i<12;i++)
			 if(m==mm[i]&&d==dd[i]) ans++;
		}
		
		nextday(m,d,w);		
	}
	printf("%d\n",ans);

	return 0;
}

 

Published 138 original articles · won praise 18 · views 7040

Guess you like

Origin blog.csdn.net/qq_924485343/article/details/104334945