网站建设的因素,一般网站做推广要多大的带宽和内存,wordpress视频播放器代码,建设项目环保备案登记网站题目描述
回文日期 - 蓝桥云课 (lanqiao.cn) 题目分析
对于此题#xff0c;我们最先想到的是暴力解法#xff0c;将每一种情况经行循环查找#xff0c;在查找的过程中记录下答案#xff0c;回文日期就是字符串判断回文#xff0c;ABABBABA型回文日期可以将回文经行特判…题目描述
回文日期 - 蓝桥云课 (lanqiao.cn) 题目分析
对于此题我们最先想到的是暴力解法将每一种情况经行循环查找在查找的过程中记录下答案回文日期就是字符串判断回文ABABBABA型回文日期可以将回文经行特判从而确定
#includebits/stdc.h
using namespace std;
int m[13] {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nx, ans, f1, f2;
string ans1, ans2;
bool is_ren(int n)
{if(n % 400 0 || (n % 100 ! 0 n 4 0))return true;return false;
}
bool flag1(string s)
{int n s.size();for(int i 0; i n / 2; i ){if(s[i] ! s[n - i - 1])return false;}ans1 s;return true;
}
bool flag2(string s)
{int n s.size();for(int i 0; i n / 2; i ){if(s[i] ! s[n - i - 1])return false;}if(s[0] s[2] s[2] s[5] s[5] s[7] s[1] s[3] s[3] s[4] s[4] s[6] s[0] ! s[1]){ans2 s;return true;}return false;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cin nx;//算出输入的年月日 int y nx / 10000;int mo nx / 100 % 100;int d nx % 100;//从输入的年开始2020是随意的数字 for(int i y; i 10000; i ){if(is_ren(i))m[2] 29;else m[2] 28;for(int j 1; j 12; j ){for(int k 1; k m[j]; k ){if(i y j 1 k 1)//如果是刚进入循环的时候因为此时当天不算故看下一天是哪一天 {if(d 1 m[mo])//下一天不跨月 {j mo;k d 1;}else if(mo 1 12)//下一天跨月不跨年 {j mo 1;k 1;}else//下一天跨年 {i y ;j 1;k 1;}}//将这一天转为字符串进行判断 string s ;s to_string(i);if(j 10)s to_string(0);s to_string(j);if(k 10)s to_string(0);s to_string (k);if(ans1.size() ! 8)flag1(s);if(ans2.size() ! 8)flag2(s);if(ans1.size() 8 ans2.size() 8)break;}if(ans1.size() 8 ans2.size() 8)break;}if(ans1.size() 8 ans2.size() 8)break;}cout ans1 \n ans2;return 0;
}