薛时锦 题解分享 · 2024/4/7
日期统计(结果填空) - 题解
套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 0
Minus 题解分享 · 2024/4/6
日期统计(结果填空) - 题解
``` #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 1
1368330567 题解分享 · 2024/4/11
日期统计(结果填空) - 题解
暴力 ``` #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 1
nihao 题解分享 · 2024/4/5
日期统计(结果填空) - 题解
最朴实无华的一集,虽然不是很优雅 ``` 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 2
haokai 题解分享 · 2024/4/12
日期统计(结果填空) - 题解
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 0
挚爱 题解分享 · 2025/3/22
日期统计(结果填空) - 题解
``` #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 2
shu 题解分享 · 2024/4/7
日期统计(结果填空) - 题解
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 2
1368330567 题解分享 · 2024/4/11
日期统计(结果填空) - 题解
求的是符合条件的日期,不知道哪里不对 ``` #include<bits/stdc++.h> using namespace std; char a[110]; int day, ans; bool check(int day) { int yy = day / 10000, mm = day / 100 % 100, dd = day % 100; if (yy == 2023) { if (mm < 1 || mm>12) return false; else { if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) { if (dd >= 1 && dd <= 31) return true; else return false; } else if (mm == 2) { if (dd >= 1 && dd <= 28) return true; else return false; } else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) { if (dd >= 1 && dd <= 30) return true; else return false; } } } else if(yy!=2023) return false; } void dfs(int t) { if (t == 9) { if (check(day)) cout << day << endl; return; } for (int i = 1; i <= 100; i++) { int x = a[i] - '0'; for (int i = 7; i >= t; i--) x *= 10; day += x; dfs(t + 1); day -= x; } } int main() { for (int i = 1; i <= 100; i++) cin >> a[i]; dfs(1); return 0; } ```
查看全文
0 0 0 1
sansmoster97 题解分享 · 2024/4/9
日期统计(结果填空) - 题解
给一个在网上临摹大佬的一种用dfs来写这道题的代码,勿喷。 原代码视频链接 https://www.bilibili.com/video/BV1j24y1w7RR/?spm_id_from=333.880.my_history.page.click&vd_source=fe0be9f851003a3111d52a41ffcc724a ``` #include <iostream> using namespace std; int cnt, a[102];//确定数量以及输入数字 bool vis[20240000];//用于去重的判断数组 //判断该日期是否为合法日期 bool check(int data) { if (vis[data])//判断该日期是否是重复日期 return false; vis[data] = true; int mm = data / 100 % 100;//取月份 int dd = data % 100;//取天数 if (mm < 1 || mm > 12) //判断月份是否在1-12之间 return false; if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) {//判断大年 if (dd < 1 || dd > 31) return false; } //判断2月特殊月份 else if (mm == 2) { if (dd < 1 || dd > 28) return false; } else if (dd < 1 || dd > 30) return false; else return true; } //使用深搜来查找日期 void dfs(int x, int sum, int data) { if (x == 100) return; if (sum == 8) { if (check(data)) { ++cnt; } return; } if (//逐位排查 sum == 0 && a[x] == 2 || sum == 1 && a[x] == 0 || sum == 2 && a[x] == 2 || sum == 3 && a[x] == 3 || sum == 4 && a[x] >= 0 && a[x] <= 2 || sum == 5 && a[x] >= 0 && a[x] <= 9 || sum == 6 && a[x] >= 0 && a[x] <= 3 || sum == 7 && a[x] >= 0 && a[x] <= 9) { dfs(x + 1, sum + 1, data * 10 + a[x]); } //这里千万不要用else,否则会导致提前出递归(调试半天才发现的问题) dfs(x + 1, sum, data); } int main() { for (int i = 0; i < 100; i++) { cin >> a[i]; } dfs(0, 0, 0); cout << cnt; return 0; } ```
查看全文
0 0 0 1
工藤新一 题解分享 · 2024/4/4
日期统计(结果填空) - 题解
``` #include <bits/stdc++.h> using namespace std; string str1="8516346707827689565614010094809128502533"; bool f(string str) { int i=0; for(char c:str1) { if(c==str[i]) ++i; if(i>=4) return true; } return false; } int main() { /* 找到第一个2023,然后把2023的3前面所有数删除。 因为要求不重复!!!最多356!!! 容易发现,满足第一个2023的日期必定满足第2、3...n个2023的日期(n>1)。 用双指针查找子序列是2023年的每一天。 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 a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},sum=0; for(int i=1;i<=12;i++) { for(int j=1;j<=a[i];j++) { char c; string str2=""; if(i<10) { // c='0'+i; str2+='0'; str2+=c; } else { // c='0'+i/10; str2+=c; c='0'+i%10; str2+=c; } if(j<10) { // c='0'+j; str2+='0'; str2+=c; } else { // c='0'+j/10; str2+=c; c='0'+j%10; str2+=c; } if( f(str2) ) ++sum; // cout<<str2; // break; } // break; } cout<<sum; return 0; } ```
查看全文
0 0 0 1