返回题解分享
讨论 / 题解分享/ 帖子详情

日期统计(结果填空) - 题解

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int nums[100] = { 5,6 ,8 ,6 ,9 ,1 ,6 ,1 ,2, 4, 9, 1, 9, 
8, 2, 3, 6, 4, 7, 7, 5, 9, 5, 0, 3, 8, 7, 5, 8, 
1, 5, 8, 6, 1, 8, 3, 0, 3, 7, 9, 2, 7 ,0 ,5 ,8,
8 ,5 ,7 ,0 ,9 ,9 ,1 ,9 ,4 ,4 ,6 ,8 ,6 ,3 ,3 ,8,
5 ,1 ,6 ,3 ,4 ,6 ,7 ,0 ,7, 8, 2, 7, 6, 8, 9, 5, 
6, 5, 6, 1, 4, 0, 1, 0, 0, 9, 4, 8, 0, 9, 1, 2, 
8, 5, 0, 2, 5, 3, 3};
int used[100];
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int flag;
int get_day(int month){
    return days[month];
}
void next_day(int &month,int &day){
    day++;
    if(day>get_day(month)){
        month++;
        day=1;
    }
}

bool allfind(char str[]){
	int k=0;
    for(int i=0;i<100;i++){
    	if(nums[i]==str[k]-'0') {
    		k++;
    		if(k==8){
    			return true;
			}
		}
	}
	return false;
}
int main(){
    int res=0;
    int month=1;
	int day=1;
    char str[8];
    sprintf(str,"2023%02d%02d",month,day);
    day=1;
    if(allfind(str)) res++;
    while(1){
        next_day(month,day); 
		char str1[8];    
        sprintf(str1,"2023%02d%02d",month,day);
        if(allfind(str1)) res++;
		if(month == 12 && day == 31) break;
    }
    cout<<res;

    return 0;
}
0 回复 0 转发 0 喜欢 7 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!