翻日历即可,不需要想太复杂,第一次提交未考虑20世纪的答案了,87分,我服了
以下是100分代码
1 #include <set> 2 #include <cstdio> 3 #include <iostream> 4 using namespace std; 5 bool check(int year){return (year%4==0&&year%100!=0)||(year%400==0);} 6 struct Date{ 7 int year,month,day; 8 Date(int year=0,int month=0,int day=0):year(year),month(month),day(day){} 9 void print(){ 10 printf("%d-",year); 11 if(month<10)printf("0%d-",month);else printf("%d-",month); 12 if(day<10)printf("0%d ",day);else printf("%d ",day); 13 } 14 void add(){ 15 day++;if(day<=28)return; 16 if(day==29&&month==2&&!check(year))day=1,month++; 17 else if(day==30&&month==2&&check(year))day=1,month++; 18 else if(day==31&&(month==4||month==6||month==9||month==11))day=1,month++; 19 else if(day==32&&(month==1||month==3||month==5||month==7||month==8||month==10))day=1,month++; 20 else if(day==32&&month==12)day=1,month=1,year++; 21 } 22 }; 23 bool compile(Date A,Date B){return (A.day==B.day&&A.month==B.month&&A.year==B.year);} 24 char s[15]; 25 int main(){ 26 scanf("%s",s+1); 27 int a=(s[1]-'0')*10+(s[2]-'0'); 28 int b=(s[4]-'0')*10+(s[5]-'0'); 29 int c=(s[7]-'0')*10+(s[8]-'0'); 30 for(Date A=Date(1960,1,1),B=Date(2060,1,1);!compile(A,B);A.add()) 31 if(compile(Date(1900+a,b,c),A)||compile(Date(2000+a,b,c),A)|| //就是这里,我服了 32 compile(Date(1900+c,a,b),A)||compile(Date(2000+c,a,b),A)|| //看到ABC<=9就把1900删了 33 compile(Date(1900+c,b,a),A)||compile(Date(2000+c,b,a),A)){ //我怕不是个是傻子 34 A.print(); 35 } 36 return 0; 37 }