wangjunze @ 2019-05-31 20:37:23
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
string month[12]={"01","02","03","04","05","06","07","08","09","10","11","12"};
string day[12]={"31","28","31","30","31","30","31","31","30","31","30","31"};
string day2[12]={"31","29","31","30","31","30","31","31","30","31","30","31"};
int to_num(string s)
{
stringstream ss(s);
int n;
ss>>n;
return n;
}
string to_string(int n)
{
string s;
stringstream ss;
ss<<n;
s=ss.str();
return s;
}
int main()
{
int cnt=0;
string s;
cin>>s;
string t;
cin>>t;
string s2=s.substr(0,4);
string t2=t.substr(0,4);
int nums=to_num(s2);
int numt=to_num(t2);
for(int i=nums;i<=numt;i++)
{
string a=to_string(i);
string b=to_string(i);
reverse(b.begin(),b.end());
string k="";
k+=a;
k+=b;
bool type1=0;
bool type2=0;
int f;
string b1="";
b1+=b[0];
b1+=b[1];
string b2="";
b2+=b[2];
b2+=b[3];
for(int j=0;j<12;j++)
{
if(b1==month[j])
{
type1=1;
f=j;
break;
}
}
if(to_num(b2)<=to_num(day[f]) && to_num(a)%4!=0)type2=1;
if(to_num(b2)<=to_num(day2[f]) && to_num(a)%4==0)type2=1;
if(k>=s && k<=t && type1==1 && type2==1)
{
//cout<<k<<endl;
cnt++;
}
}
cout<<cnt;
return 0;
}
以上是代码(那两个函数是用来在字符串和数字之间变化的)
by 吴勉之 @ 2019-05-31 20:40:33
洛谷似乎可能也许大概maybe用Linux系统