思路:
循环2023的每一天,一共八位数;年份是确定的,只需要循环月份和天数,注意这里已知2023的2月份天数为28天。用b数组
int b[8]={2,0,2,3,month/10,month%10,d/10,d%10};//枚举2023的每一天来和已知数据的八位数字比较
存储每一天,再 i 循环已知数组,将每一个元素都看作一次起点。将 j 变量循环数组 b ,如果 j 能循环到 8 说明有符合条件的日期,将 ans ++ 。
借鉴代码:
#include <iostream>
using namespace std;
int main()
{
int month,day,i,j,sum=0;
int a[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};
for(month=1;month<=12;month++)
{
if(month==2)//可以确定2023的2月只有28天
day=28;
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)//31天的月份
day=31;
else//30的月份
day=30;
for(int d=1;d<=day;d++)
{
j=0;
int b[8]={2,0,2,3,month/10,month%10,d/10,d%10};//枚举2023的每一天来和已知数据的八位数字比较
for(i=0;i<100;i++)//从前往后,以每个数都为一次起点
{
if(a[i]==b[j])
j++;
if(j==8)//如果这八位数字都满足就 sum++
{
// cout<<sum<<"sum"<<endl;
sum++;
break;
}
}
}
}
cout<<sum;
return 0;
}