1.题目
2.参考代码
#include<bits/stdc++.h>
using namespace std;
int arr[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 days[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};
int ans = 0;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
for(int i=1;i<=12;i++){
for(int j = 1;j<=days[i];j++){
int date[8] = {2,0,2,3,i/10,i%10,j/10,j%10};
int k = 0;
for(int p = 0;p<100;p++){
if(arr[p] == date[k]){
k++;
if(k==8){
ans++;
break;
}
}
}
}
}
cout<<ans;
return 0;
}
3.代码分析
- 定义了一个数组arr,存储题目所给的数组元素。
- 定义了一个days数组,存储了每个月的天数。
- 初始化ans为0,用来记录符合条件的日期数量。
- 使用循环遍历1到12月。
- 在每个月内,再使用循环遍历该月的每一天。
- 定义一个date数组,存储日期的数字表示。
- 使用循环遍历arr数组,通过比较日期数组和arr数组的元素,来检查是否相符。
- 如果符合日期条件,ans加1。
- 输出ans的值。
考察点为暴力、枚举等。