题目点这里

思路:

根据题目意思模拟就行

收获:

利用stringstream将数字转为字符串

int y = 2020;
 stringstream ss;
   string s;
   ss<<y;
   ss>>s;

代码:

#include<bits/stdc++.h>

using namespace std;
int lyear[13] = {
   31,29,31,30,31,30,31,31,30,31,30,31};
int year[13] = {
   31,28,31,30,31,30,31,31,30,31,30,31};
//判断日期是否属于合法日期
vector<string> ans;
bool isleap(int y)
{
   
    return (y%4==0&&y%100)||y%400==0;
}
string bestr(int y,string m,string d)
{
   
   stringstream ss;
   string s;
   ss<<y;
   ss>>s;
   s+='-';
   s+=m;
   s+='-';
   s+=d;
   return s;
}
bool check(int y,int m,int d)
{
   
    if(m<=0||d<=0||y<=0||m>12||d>31) return false;
    if(isleap(y)) 
    {
   
        if(d>lyear[m-1]) return false;
        else return true;
    }
    else 
    {
   
        if(d>year[m-1]) return false;
        else return true;
    }
}

string add(char a,char b)
{
   
    string s;
    s+=a;
    s+=b;
    return s;
}

void change(string a,string b,string c)
{
   
    //年份
    int y = 1900 + (a[0]-'0')*10 + a[1]-'0';
    if(y<1960) y = 2000+(a[0]-'0')*10 + a[1]-'0';
    //月
    int m  = (b[0]-'0')*10 + b[1]-'0';
    //日
    int d =  (c[0]-'0')*10 + c[1]-'0';
    if(check(y,m,d)) 
    {
   
        ans.push_back({
   bestr(y,b,c)});
    }
}
int main()
{
   
    string s;
    cin>>s;
    string a,b,c;
    a = add(s[0],s[1]);
    b = add(s[3],s[4]);
    c = add(s[6],s[7]);
    // cout<<a<<" "<<b<<" "<<c<<endl;
    change(a,b,c);
    change(c,b,a);
    change(c,a,b);
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
    return 0;
}