题目链接https://www.luogu.com.cn/problem/P8651
枚举
最好用上tuple来存三元的
也许有更好的方法,我写的比较复杂
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#define ll long long
const ll N = 1e5 + 10;
//ll n,m;
//ll op[N];
struct ii{
ll ye;
ll mo;
ll da;
friend bool operator<(ii &w1,ii &w2){
if(w1.ye != w2.ye)
return w1.ye < w2.ye;
else{
if(w1.mo != w2.mo) return w1.mo < w2.mo;
else{
return w1.da < w2.da;
}
}
}
}pp[N];
bool check1(ll yy){
if(yy % 400 == 0 || (yy % 4 == 0 && yy % 100 != 0)) return true;
else return false;
}
bool check(ll yy,ll mm,ll dd){
if(mm > 12 || mm < 1) return false;
if(dd > 31 || dd < 1) return false;
if(mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12){
if(dd >= 1 && dd <= 31) return true;
else return false;
}
if(mm == 4 || mm == 6 || mm == 9 || mm == 11){
if(dd >= 1 && dd <= 30) return true;
else return false;
}
if(check1(yy)){//闰月
if(dd >= 1 && dd <= 29) return true;
else return false;
}
else{
if(dd >= 1 && dd <= 28) return true;
else return false;
}
}
void solve(){
std::string a;
std::cin >> a;
std::map<std::tuple<ll,ll,ll>,ll> op;
std::string aa = a.substr(0,2);
std::string bb = a.substr(3,2);
std::string cc = a.substr(6,2);
std::string dp[] = {aa,bb,cc};
ll re = 0;
for(ll i = 0; i <= 2; i ++){
for(ll j = 0; j <= 2; j ++){
for(ll k = 0; k <= 2; k ++){
if(i != j && i != k && j != k){
if(i == 0 && j > k) continue;
if(i == 1) continue;
ll uu = std::stoll(dp[i]);
std::string a1;
if(uu >= 60){
a1 = "19" + dp[i];
}
else a1 = "20" + dp[i];
ll y1 = std::stoll(a1);
ll m1 = std::stoll(dp[j]);
ll d1 = std::stoll(dp[k]);
// std::cout << y1 << " " << m1 << " " << d1 << "\n";
if(check(y1,m1,d1)){
// std::cout << "正确的\n";
if(op[{y1,m1,d1}] == 0){
pp[++re] = {y1,m1,d1};
// printf("%.4lld-%.2lld-%.2lld\n",y1,m1,d1);
}
op[{y1,m1,d1}] ++;
}
}
}
}
}
std::sort(pp + 1,pp + 1 + re);
for(ll i = 1; i <= re; i ++){
printf("%.4lld-%.2lld-%.2lld\n",pp[i].ye,pp[i].mo,pp[i].da);
}
return ;
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}