|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 player-none 于 2025-3-15 12:20 编辑
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int getdays(int y,int m){
- int a;
- if(m==1){
- a=31;
- }else if(m==2){
- if(y%400==0)a=29;
- else if(y%100==0)a=28;
- else if(y%4==0)a=29;
- else a=28;
- }else if(m==3){
- a=31;
- }else if(m==4){
- a=30;
- }else if(m==5){
- a=31;
- }else if(m==6){
- a=30;
- }else if(m==7){
- a=31;
- }else if(m==8){
- a=31;
- }else if(m==9){
- a=30;
- }else if(m==10){
- a=31;
- }else if(m==11){
- a=30;
- }else{
- a=31;
- }
- return a;
- }
- bool ishuiwen(int x){
- string s=to_string(x);
- string sb=s;
- reverse(s.begin(),s.end());
- return sb==s;
- }
- int main()
- {
- int date1,date2,y,m,d,count=0;
- cin>>date1>>date2;
- y=date1/10000;
- m=date1%10000/100;
- d=date1%100;
- while(y*10000+m*100+d<=date2){
- if(ishuiwen(y*10000+m*100+d)){
- count+=1;
- }
- int a=getdays(y,m);
- if(d+1<=a){
- d+=1;
- }else if(m+1<=12){
- d=1;
- m+=1;
- }else{
- d=1;
- m=1;
- y+=1;
- }
- }
- cout<<count;
- return 0;
- }
复制代码
其实题目还简单,就是代码量大,敲着累……不过我认为这段代码非常具有……可以让我好好记录一番的特点。 |
|