1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 using namespace std; 5 int judge(int x) 6 { 7 if((x%4==0&&x%100!=0)||(x%400==0)) 8 return 1; 9 return 0; 10 } 11 int uy[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 12 int y[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; 13 int main() 14 { 15 int a[201]; 16 int i,j,k; 17 a[0]=1; 18 int m,t,w,y1,y2,d; 19 cin>>m>>t>>w>>y1>>y2; 20 for(i=1;i<=y2-1850;i++) 21 { 22 if(judge(i+1850-1)) 23 a[i]=(a[i-1]+2)%7; 24 else 25 a[i]=(a[i-1]+1)%7; 26 } 27 for(i=0;i<=y2-1850;i++) 28 a[i]++; 29 for(i=y1-1850;i<=y2-1850;i++) 30 { 31 bool flag=0; 32 d=0; 33 if(judge(i+1850)) 34 { 35 for(k=1;k<m;k++) 36 d+=y[k]; 37 flag=0; 38 } 39 else 40 { 41 for(k=1;k<m;k++) 42 d+=uy[k]; 43 flag=1; 44 } 45 int f,x,h=0; 46 f=d%7; 47 x=(a[i]-1+f)%7+1; 48 //cout<<x<<endl; 49 if(x>w) 50 { 51 if(t==1) 52 h+=(7-x+1+w); 53 else 54 { 55 h+=(7-x+1+w+(t-1)*7); 56 } 57 } 58 else if(x<w) 59 { 60 if(t==1) 61 h+=(w-x+1); 62 else 63 { 64 h+=(7-x+1+w+(t-2)*7); 65 } 66 } 67 else 68 { 69 if(t==1) 70 h=1; 71 else 72 h+=(7-x+1+(t-2)*7+w); 73 } 74 if(!flag) 75 { 76 if(h>y[m]) 77 { 78 cout<<"none"<<endl; 79 continue; 80 } 81 } 82 else 83 { 84 if(h>uy[m]) 85 { 86 cout<<"none"<<endl; 87 continue; 88 } 89 } 90 //cout<<d<<endl; 91 cout<<1850+i<<‘/‘; 92 printf("%02d",m); 93 cout<<‘/‘; 94 printf("%02d\n",h); 95 } 96 //cout<<a[2014-1850]<<" "<<a[2015-1850]; 97 }
原文:http://www.cnblogs.com/a1225234/p/4802759.html