FLYFISH 题解分享 · 2024/4/8
顺子日期(结果填空) - 题解
cpp include include include using namespace std; int cmd(int year, int a, int b, int c, int d) { if (year == a - 1 && a == b - 1) return 1; ``` else if (a == b - 1 && b == c - 1) return 1; else if (b == c - 1 && c == d - 1) return 1; else return 0; ``` } int cmd1( int b, int c, int d) { ``` if (b == c + 1 && c == d + 1) return 1; else if (b == c - 1 && c == d - 1) return 1; else return 0; ``` } int main() { int num = 0, year = 2; int a, b, c, d; for (int mouth = 1; mouth 28) break; } else { if (day > 30) break; } a = mouth / 10, b = mouth % 10, c = day / 10, d = day % 10; ``` if (cmd(year, a, b, c, d)) { cout << 2022 << setw(2) << setfill('0') << mouth << setw(2) << setfill('0') << day << endl;; num++; } } cout << num << endl; return 0; ``` }
查看全文
0 0 1 16
sun 题解分享 · 2024/4/12
顺子日期(结果填空) - 题解
如果不会计算机编程,我们还可以使用”大脑计算机“😄 1. 2022 012x--->10个 2. 2022 0234--->不满足(一个月最多才31天) 3. ``` 2022 0345,三月只能是0345,但是一个月最多31天,所以三月没有,以此类推04,05,06,07,08,09月都没有我们想要的。 ``` 4. 2022 1012--->1个(10月,0后面必须跟12才能满足题意) 5. 2022 1123--->1个(11月,1后面必须是23) 6. ``` 2022 1230和2022 1231--->2个 ``` 综上: 10+1+1+2=14 填空题有时候脑力比编程快一些 希望对大家有所帮助
查看全文
0 0 1 5
acmer10 题解分享 · 2024/4/3
顺子日期(结果填空) - 题解
``` #include<iostream> #include<cstring> #include<algorithm> using namespace std; int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool check(string s) { if((s[1]-s[0]==1&&s[2]-s[1]==1)||(s[2]-s[1]==1&&s[3]-s[2]==1))return true; return false; } int main() { int m=1; int d=1; int cnt=0; while(m<13) { string s=""; if(m<10)s="0"+to_string(m); else s+=to_string(m); if(d<10)s="0"+to_string(d); else s+=to_string(d); if(check(s))cnt++; if(d+1<=mon[m]) d++; else { d=1; m++; } } cout<<cnt<<endl; return 0; } ```
查看全文
0 0 1 2
hxq 题解分享 · 2025/2/1
顺子日期(结果填空) - 题解
``` #include<bits/stdc++.h> using namespace std; char str[15]; int main() { int ans=0; for(int year=2022;year<=2022;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+1,"%d%02d%02d",year,month,day); for(int k=4;k+2<=8;k++) { if(str[k+2]-str[k+1]==1&&str[k+1]-str[k]==1) { ans++; break; } } } cout<<ans; return 0; } ```
查看全文
0 0 0 11
AuroraYxh 题解分享 · 2024/4/6
顺子日期(结果填空) - 题解
```cpp ❤️ #include <bits/stdc++.h> using namespace std; int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool isleap(int y) { if (y % 400 == 0 || y % 4 == 0 && y % 100) return true; return false; } bool chk(string str) { for (int i = 0; i + 2 < str.size(); ++i) { if (str[i] + 1 == str[i + 1] && str[i + 1] + 1 == str[i + 2]) return true; } return false; } int main() { int cury = 2022, curm = 1, curd = 1; if (isleap(cury)) month[2] = 29; else month[2] = 28; int res = 0; while (cury == 2022) { char str[20]; sprintf(str, "%d%02d%02d", cury, curm, curd); // 只可以接收char str[N] if(chk(str)) { ++res; cout << str << endl; } string stringstr = str;//char str[N]强转为string ++curd; if (curd > month[curm]) { curd = 1; ++curm; } if (curm > 12) { curm = 1; ++cury; } } cout << res << endl; return 0; } ```
查看全文
0 0 0 22
kagami_sama 题解分享 · 2024/4/7
顺子日期(结果填空) - 题解
``` #include <iostream> using namespace std; int morth[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31}; int idx; bool check(int n) { if (n % 100 > 31 || n % 100 == 0) return false; if (n / 100 > 12|| n / 100 == 0) return false; if (morth[n / 100] < n % 100) return false; return true; } bool cmp(int a, int b, int c, int d) { if (a + 1 == b && b + 1 == c) return true; if (b + 1 == c && c + 1 == d) return true; return false; } int main() { for (int i = 1; i <= 1231; i ++ ) { if (check(i)) { int a, b, c, d; a = i /1000, b = i / 100 % 10, c = i % 100 / 10, d = i % 10; //cout << a << " " << b << " " << c <<" " << d << endl; if(cmp(a,b,c,d)) { cout << "2022" << a << b << c << d << endl; idx ++ ; } } } cout << idx << endl; return 0; } ```
查看全文
0 0 0 18
freefreefreer 题解分享 · 2024/4/9
顺子日期(结果填空) - 题解
include using namespace std; int shunzi( int a, int b, int c, int d) { ``` if (a == b - 1 && b == c - 1) return 1; else if (b == c - 1 && c == d - 1) return 1; else return 0; ``` } int main() { int num = 0; int a, b, c, d; for (int mouth = 1; mouth 28) break; } else { if (day > 30) break; } a = mouth / 10, b = mouth % 10, c = day / 10, d = day % 10; if (shunzi(a, b, c, d)) { printf("2022-%d%d-%d%d\n",a, b, c, d); num++; } } cout << num << endl; return 0; }
查看全文
0 0 0 7
Dervish 题解分享 · 2024/4/7
顺子日期(结果填空) - 题解
include using namespace std; int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; bool check_valid(int date) { int y = date/10000; int m = date%10000/100; int d = date%10000%100; if(m 12) return false; if(d months[m]) return false; if(m == 2) { if(y%4==0&&y%100!=0||y%400==0) months[2] = 29; if(d>months[2]) return false; } return true; } bool check(string s) { for (int i = 0; i < s.size(); i ++ ) { if(s[i] - '0' + 1 = s[i + 1] - '0' && s[i + 1] - '0' + 1 = s[i + 2] - '0') return true; } return false; } int main() { int res = 0; for (int i = 20220101; i <= 20221231; i ++ ) { if(check_valid(i)) { string s = to_string(i); if(check(s)) res++; } } cout << res; return 0; }
查看全文
0 0 0 5
fpy游戏人生 题解分享 · 2024/4/8
顺子日期(结果填空) - 题解
有一个问题就是判断顺子那段有点不懂,有无大佬解释一下为什么 typedef long long ll; using namespace std; char str[15]; int main() { int cnt =0,flag=0,ans=0; for(int year=2022;year<=2022;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+1,"%d%02d%02d",year,month,day); //判断顺子 for(int k=4;k+2<=8;k++) { ``` if(str[k+2]-str[k+1]==1&&str[k+1]-str[k]==1) { puts(str+1); ans++; break; } ``` } } cout<<ans; }
查看全文
0 0 0 1