题解分享
题解分享简介
日期统计(结果填空) - 题解
套day1模板+sprinf函数
```
#include
using namespace std;
int a[101];
int main(){
for (int i = 1;i <= 100; ++i) {
scanf("%d",&a[i]);
}
char str[8];
int cnt = 0;
int flag = 0;
for (int i = 2023; i <= 2023; ++i) {
for (int j = 1; j <= 12; ++j) {
for (int k = 1; k <= 31; ++k) {
if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12){
}else if (j == 2){
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0){
if (k > 29) break;
}else{
if (k > 28) break;
}
}else {
if (k > 30) break;
}
sprintf(str,"%04d%02d%02d",i,j,k);
int m = 0;
for(int n = 1; n <= 100; ++n) {
if (a[n] == (str[m] - '0')){
m++;
if (m == 8) break;
}
}
if (m == 8) flag = 1;
if (flag == 1) {
cnt++;
flag = 0;
}
}
}
}
cout << cnt;
return 0;
}`
```
查看全文
0
0
5
13
日期统计(结果填空) - 题解
```
#include <bits/stdc++.h>
#include <string>
using namespace std;
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};
int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int ans = 0;
for(int month = 1 ; month <= 12 ; month ++)
{
for(int day = 1 ; day <= days[month] ; day ++ )
{
int date[8] = { 2 , 0 , 2 , 3 , month / 10 , month % 10 , day / 10 , day % 10} ; // 枚举每一个日期
int index = 0 ;
for(int i = 0 ; i < 100 ; i ++ )
{
if(a[i] == date[index]) // 逐位检查日期
{
index ++ ;
if(index == 8)
{
ans ++;
break ;
}
}
}
}
}
cout << ans << endl ;
return 0;
}
```
这种逐个检查的方式不会出现重复
查看全文
0
0
4
17
日期统计(结果填空) - 题解
最朴实无华的一集,虽然不是很优雅
```
import java.util.HashSet;
public class Main {
static int mouths[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public static void main(String[] args) {
int[] array = new int[] { 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 };
HashSet<Integer> hashSet = new HashSet<Integer>();
for (int a = 0; a < 100; a++) {
if (array[a] != 2)
continue;
for (int b = a + 1; b < 100; b++) {
if (array[b] != 0)
continue;
for (int c = b + 1; c < 100; c++) {
if (array[c] != 2)
continue;
for (int d = c + 1; d < 100; d++) {
if (array[d] != 3)
continue;
for (int e = d + 1; e < 100; e++) {
for (int f = e + 1; f < 100; f++) {
for (int g = f + 1; g < 100; g++) {
for (int h = g + 1; h < 100; h++) {
int tem = array[e] * 1000 + array[f] * 100 + array[g] * 10 + array[h];
if (check(array[e] * 10 + array[f],array[g] * 10 + array[h])) {
hashSet.add(tem);
}
}
}
}
}
}
}
}
}
System.out.println(hashSet.size());
}
static boolean check(int mouth ,int day) {
if(mouth<=12&&mouth>0&&day>0&&day<=mouths[mouth]) {
return true;
}
return false;
}
}
```
查看全文
0
0
1
16
日期统计(结果填空) - 题解
include
using namespace std;
int main(){
int num[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 cnt = 0;
int a= 0;
for(int month=1;month<=12;month++){
for(int day=1;day<=31;day++){
if(month == 2){
if(day==29) break;
}
if(month ==4||month ==6||month ==9||month == 11 ){
if(day==31) break;
```
}
for(int i=0;i<100;i++){
if(a==0&&num[i] == 2) {a=1; continue;} // 必须跳过 要不会一个数重复算 比如2023 11 11 一个1 用作四个
if(a==1&&num[i] == 0) {a=2;continue;}
if(a==2&&num[i] == 2) {a=3; continue;}
if(a==3&&num[i] == 3) {a=4; continue;}
if(a==4 && month/10== num[i] ) {a=5;continue;}
if(a==5 && num[i] == month%10) {a=6;continue;}
if(a==6 && num[i] == day/10) { a=7;continue;}
if(a==7 && num[i] == day%10) {cnt++; break;}
}
a=0;
}
}
cout << cnt;
```
}
纯小白
查看全文
0
0
1
12
日期统计(结果填空) - 题解
暴力
```
#include <bits/stdc++.h>
using namespace std;
char a[101];
int main()
{
for (int i = 1; i <= 100; i++)
cin >> a[i];
int daysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int ans = 0;
for (int month = 1; month <= 12; month++)
{
for (int day = 1; day <= daysInMonth[month]; day++)
{
int dateSeq[8] = { 2, 0, 2, 3, month / 10, month % 10, day / 10, day % 10 };
int k = 0;
for (int i = 1; i <= 100; i++)
{
int x = a[i] - '0';
if (x == dateSeq[k])
{
k++;
if (k == 8)
{
ans++;
break;
}
}
}
}
}
cout << ans;
return 0;
}
```
---
查看全文
0
0
1
9
日期统计(结果填空) - 题解
```
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
int a[100], ans;
bool vis[20240000];
bool check(int data)
{
if(vis[data])//日期已经访问过了
{
return false;
}
vis[data] = 1;
int mm = data / 100 % 100;
int dd = data % 100;
if(mm<1 || mm > 12)//月份是否合法
{
return false;
}
if(mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12)
{
if(dd>=1 && dd<= 31)
{
return true;
}
}
else if(mm == 2)
{
if(dd >= 1 && dd <= 28)
{
return true;
}
}
else if(dd >= 1 && dd <= 30)
{
return true;
}
else
{
return false;
}
}
void dfs(int x,int pos,int data)//x为遍历的下标 ,pos为当前八位遍历下标的位置,data为日期
{
if(x == 100)
{
return ;
}
if(pos == 8)
{
if(check(data))
{
++ans;
}
return ;
}
if((pos == 0 && a[x] == 2) ||
(pos == 1 && a[x] == 0) ||
(pos == 2 && a[x] == 2) ||
(pos == 3 && a[x] == 3) ||
(pos == 4 && a[x] >= 0 && a[x] <= 1) ||
(pos == 5 && a[x] >= 0 && a[x] <= 9) ||
(pos == 6 && a[x] >= 0 && a[x] <= 3) ||
(pos == 7 && a[x] >= 0 && a[x] <= 9))
{
dfs(x+1,pos+1,data*10+a[x]);//选上了
}
dfs(x+1,pos,data);
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
for(int i = 0;i < 100;i++)
{
cin>>a[i];
}
dfs(0,0,0);
cout<<ans<<endl;
return 0;
}
```
查看全文
0
0
0
15
日期统计(结果填空) - 题解
include
using namespace std;
int main()
{
int a[] = {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 ans = 0;
int day1[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int moth = 1; moth <= 12; moth ++ )
for(int day = 1; day <= day1[moth]; day ++ ) {
int da[] = {2, 0, 2, 3, moth / 10, moth % 10, day / 10, day % 10};
int k = 0;
for(int i = 0; i < 100; i ++ ) {
if(a[i] == da[k])
k ++ ;
if(k == 8) {
ans ++ ;
break;
}
}
}
cout << ans << endl;
}
查看全文
0
0
0
19
日期统计(结果填空) - 题解
```
#include<bits/stdc++.h>
using namespace std;
int a[101];
int cnt;
int main()
{
for(int i=1;i<=100;i++)
{
cin>>a[i];
}
char str[8];
for(int year=2023;year<=2023;year++)
for(int month=1;month<=12;month++)
for(int day=1;day<=31;day++)
{
if(month==1||month==3||month==5||month==7||month==8
||month==10||month==12);
else if(month==2)
{
if(year%4==0&&year%100!=0||year%400==0)
{
if(day>29) break;
}
else
{
if(day>28) break;
}
}
else
{
if(day>30) break;
}
sprintf(str,"%d%02d%02d",year,month,day);
int m=0;
for(int n=1;n<=100;n++)
{
if(a[n]==(str[m]-'0'))
{
m++;
if(m==8)
{
cnt++;
break;
}
}
}
}
cout<<cnt;
return 0;
}
```
查看全文
0
0
0
7
日期统计(结果填空) - 题解
```
#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
15
日期统计(结果填空) - 题解
Python代码
根据此文章思路改写为python代码;
https://blog.csdn.net/weixin_68629353/article/details/136271767
```
# 初始化数组
array = [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]
# 每个月的天数
days_in_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# 初始化答案变量
ans = 0
# 遍历每个月
for month in range(1, 13): # i为月份,最大取12
# 遍历每个月的每一天
for day in range(1, days_in_month[month] + 1): # j为日数,最大取days_in_month对应数值
# 构造日期序列
date_seq = [2, 0, 2, 3, month // 10, month % 10, day // 10, day % 10]
# 检查日期序列是否存在于数组中
k = 0
for num in array:
if num == date_seq[k]:
k += 1
if k == 8:
ans += 1
break # 找到完整的序列,跳出内层循环
# 输出结果
print(ans)
```
查看全文
0
0
0
14



