标签:span tle str log bsp 整数 lag i++ title
给定年月,打印当月的月历表。
2006 5
Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
1 #include<iostream> 2 using namespace std; 3 int bgyear,bgmonth,bgday; 4 int enyear,enmonth,enday; 5 int month[21]={0,31,28,31,30,31,30,31,31,30,31,30,31};//非闰年 6 int rmonth[21]={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年 7 int flag=1; 8 int tot=0; 9 int dow=1; 10 string week[8]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; 11 int main() 12 { 13 cin>>enyear>>enmonth; 14 bgyear=1900; 15 bgmonth=1; 16 bgday=1; 17 for(int i=1900;i<=enyear;i++)//寻找年数上的差异 18 { 19 if((i%4==0&&i%100!=0)||(i%400==0)) 20 { 21 for(int j=1;j<=12;j++) 22 { 23 for(int k=1;k<=rmonth[j];k++) 24 { 25 if(i==enyear&&j==enmonth) 26 { 27 int bj=0; 28 cout<<"Sun Mon Tue Wed Thu Fri Sat"<<endl; 29 for(int i=1;i<=dow;i++) 30 { 31 if(dow==7)break; 32 bj++; 33 for(int i=1;i<=3;i++) 34 cout<<" "; 35 cout<<" "; 36 }//确定第一个数的位置 37 for(int k=1;k<=rmonth[j];k++) 38 { 39 if(k<10) 40 { 41 if(bj!=6&&k!=rmonth[j]) 42 cout<<" "<<k<<" "; 43 else 44 { 45 cout<<" "<<k; 46 } 47 bj++; 48 if(bj==7) 49 { 50 cout<<endl; 51 bj=0; 52 } 53 } 54 else 55 { 56 if(bj!=6&&k!=rmonth[j]) 57 cout<<" "<<k<<" "; 58 else 59 { 60 cout<<" "<<k; 61 } 62 if(k==rmonth[j])return 0; 63 bj++; 64 if(bj==7) 65 { 66 cout<<endl; 67 bj=0; 68 } 69 } 70 } 71 return 0; 72 }//边界条件 73 dow++; 74 if(dow==8) 75 dow=1; 76 77 } 78 79 } 80 }//闰年 81 else 82 { 83 for(int j=1;j<=12;j++) 84 { 85 for(int k=1;k<=month[j];k++) 86 { 87 if(i==enyear&&j==enmonth) 88 { 89 int bj=0; 90 cout<<"Sun Mon Tue Wed Thu Fri Sat"<<endl; 91 for(int i=0;i<=dow-1;i++) 92 { 93 if(dow==7)break; 94 if(bj==6)break; 95 bj++; 96 for(int i=1;i<=3;i++) 97 cout<<" "; 98 cout<<" "; 99 }//确定第一个数的位置 100 for(int k=1;k<=month[j];k++) 101 { 102 if(k<10) 103 { 104 if(bj!=6&&k!=month[j]) 105 cout<<" "<<k<<" "; 106 else 107 { 108 cout<<" "<<k; 109 } 110 bj++; 111 if(bj==7) 112 { 113 cout<<endl; 114 bj=0; 115 } 116 } 117 else 118 { 119 if(bj!=6&&k!=month[j]) 120 cout<<" "<<k<<" "; 121 else 122 { 123 cout<<" "<<k; 124 } 125 bj++; 126 if(bj==7) 127 { 128 cout<<endl; 129 bj=0; 130 } 131 if(k==month[j])return 0; 132 } 133 } 134 return 0; 135 }//边界条件 136 dow++; 137 if(dow==8) 138 dow=1; 139 } 140 141 142 143 144 } 145 146 } 147 } 148 }
标签:span tle str log bsp 整数 lag i++ title
原文地址:http://www.cnblogs.com/zwfymqz/p/6539488.html