View Code of Problem 8

#include<iostream>
using namespace std;


int main(){
	int n;
	cin>>n;

	while(n--){
		char year[12][32];
		char car[15];
	
		char carnum;
		int pass=0;
		int k=0;
		
		cin>>car;
		for(int i=0;car[i]!='\0';i++){
		carnum=car[i];
		}
	
		int is_2=0;
		int is_30=0;
		char num[10]={'1','2','3','4','5','6','7','8','9','0'};
		for(int i=0;i<12;i++){
			is_2=0;
			is_30=0;
			for(int j=0;j<31;j++){
				if(i==1){
					is_2=1;
				}
				if(is_2==1&&j==27){
					year[i][j]='8';
					break;
				}
				if(i==3||i==5||i==8||i==10){
				is_30=1;
				}
				if(is_30==1&&j==29){
					year[i][j]='0';
					break;
				}
				else{
				year[i][j]=num[j%10];
				}
			
			}
		}
		for(int i=0;i<12;i++){
			for(int j=0;year[i][j]!='\0';j++){
				//cout<<year[i][j]<<" ";
			}
			//cout<<"\n";
		}
		for(int i=0;i<12;i++){
			for(int j=0;year[i][j]!='\0';j++){
				if(carnum-'0'!=0){
			
					if(year[i][j]-carnum==1||year[i][j]-carnum==-1){
						pass++;
					}
				}
				else{
					if(year[i][j]-'1'==0){
						pass++;
					}
					else if(year[i][j]-'9'==0){
						pass++;
					}
				}

			}
		}
		cout<<365-pass;
	}
	
	
}

Double click to view unformatted code.


Back to problem 8