AcWing 1229. 日期问题
原题链接
简单
作者:
Codecat
,
2021-03-20 19:02:58
,
所有人可见
,
阅读 293
#include<iostream>
#include<cstring>
using namespace std;
string s;
int days[4];
int months[13] = {31,28,31,30,31,30,31,31,30,31,30,31};
int year;
int month;
int day;
bool check(int date){
year = date / 10000;
month = date %10000/100;
day = date %100;
if(!month || month >13 || !day)return false;
if(month != 2 && day > months[month])return false;
if(month == 2){
bool flag = year % 4 == 0 && year % 100 || year % 400 == 0;
if(day > flag+28)return false;
}
return true;
}
int main(){
int a,b,c;
scanf("%d/%d/%d",&a,&b,&c);
for(int i=19600101;i<=20591231;i++){
if(check(i)){
if((year%100==a&&month==b&&day==c)||(month==a&&day==b&&year%100==c)||(day==a&&month==b&&year%100==c)){
printf("%d-%02d-%02d\n",year,month,day);
}
}
}
return 0;
}
作者:Anjor
链接:https://www.acwing.com/problem/content/discussion/content/2094/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。