UIT2024_Calendar/stu2024/计科2401常迦鑫.cpp
2024-12-07 16:23:34 +08:00

602 lines
12 KiB
C++

#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#include<string>
#include<iostream>
int run (int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
{
return 1;
}
return 0;
}
int rq (int n,int y,int r)
{
if (y <= 2)
{
y += 12;
n--;
}
int k = n % 100;
int j = n / 100;
int h = (r + 13 * (y + 1) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
if (y > 12)
{
y -= 12;
n++;
}
h--;
if(h==-1)
{
h=6;
}
if((n==1582&&y==10&&r<=4)||(n==1582&&y<10)||(n<1582))
{
switch(h)
{
case 6:h=2;break;
case 5:h=1;break;
case 4:h=0;break;
case 3:h=6;break;
case 2:h=5;break;
case 1:h=4;break;
case 0:h=3;break;
}
}
return h;
}
int dy (int n,int y)
{
if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)
{
return 31;
}else if(y==2)
{
if(run(n))
{
return 29;
}
return 28;
}else
return 30;
}
int main()
{
while(1)
{
for(int f=1000;f>=0;f--)
{
cout<<endl;
}
cout<<endl;
wen1:
cout<<"1.查询日期:"<<endl;
cout<<"2.判断闰年:"<<endl;
cout<<"3.查看某年日历:"<<endl;
cout<<"4.退出:"<<endl<<endl<<endl;
string a;
cin>>a;
if(a=="1")
{
int year, month, day;
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout <<endl<< "请输入年、月、日:" << endl;
cin >> year >> month >> day;
if(month>12||day>31)
{
goto wen;
}
char week[8][10] = {"周日","周一","周二","周三","周四","周五","周六"};
int h=rq(year,month,day);
for(int f=1000;f>=0;f--)
{
cout<<endl;
}
cout<<endl<<year<<""<<month<<""<<day<<"日是"<<week[h]<<endl;
}else if(a=="2")
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<endl<<"请出入你想查询的年份:"<<endl;
int n ;
cin>>n;
cout<<endl;
if(run(n))
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<n<<"年是闰年"<<endl;
goto wen;
}else
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<n<<"年不是闰年"<<endl<<endl;
goto wen;
}
}else if(a=="3")
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
wen2:
cout<<"1.单行输出"<<endl;
cout<<"2.双行输出"<<endl;
string e;
cin>>e;
if(e=="1")
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<"请输入你想查询的年份:"<<endl;
int year1;
cin>>year1;
if(year1!=1582){
char week1[8][10] = {"周日","周一","周二","周三","周四","周五","周六"};
char yue[20][20] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
for(int i=0;i<12;i++)
{
cout<<" "<<yue[i]<<endl;
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<endl;
int test=rq(year1,i+1,1);
int t2=1;
for(int j=0;j<7;j++)
{
if(j==test)
{
cout<<"0"<<t2<<" ";
t2++;
test++;
}else
{
cout<<" ";
}
}
cout<<endl;
int t3=1;
for(int j=t2;j<=dy(year1,i+1);j++,t2++)
{
if(t3==8)
{
cout<<endl;
t3=1;
}
if(j<10)
{
cout<<"0"<<t2<<" ";
}else
{
cout<<t2<<" ";
}
t3++;
}
cout<<endl;
}
cout<<endl;
}else
{
cout<<"请输入你想查询的年份:"<<endl;
int year1=1582;
char week1[8][10] = {"周日","周一","周二","周三","周四","周五","周六"};
char yue[20][20] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
for(int i=0;i<12;i++)
{
cout<<" "<<yue[i]<<endl;
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<endl;
int test=rq(year1,i+1,1);
int t2=1;
for(int j=0;j<7;j++)
{
if(i==9&&j==5)
{
t2=15;
}
if(j==test)
{
if(t2<10)
{
cout<<"0"<<t2<<" ";
}else
{
cout<<t2<<" ";
}
t2++;
test++;
}else
{
cout<<" ";
}
}
cout<<endl;
int t3=1;
for(int j=t2;j<=dy(year1,i+1);j++,t2++)
{
if(t3==8)
{
cout<<endl;
t3=1;
}
if(j<10)
{
cout<<"0"<<t2<<" ";
}else
{
cout<<t2<<" ";
}
t3++;
}
cout<<endl;
}
cout<<endl;
}
}else if(e=="2")
{
for(int f=1000;f>=0;f--)
{
cout<<endl;
}
cout<<"请输入你想要查询的年份:"<<endl;
int year1;
cin>>year1;
if(year1!=1582){
char week1[8][10] = {"周日","周一","周二","周三","周四","周五","周六"};
char yue[20][20] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
for(int i=0;i<12;i+=2)
{
int ttt;
cout<<" "<<yue[i]<<" "<<yue[i+1]<<endl;
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<" ";
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<endl;
int test1=rq(year1,i+1,1),test2=rq(year1,i+2,1);
int t2=1,t22=1;
for(int j=0;j<7;j++)
{
if(j==test1)
{
cout<<"0"<<t2<<" ";
t2++;
test1++;
}else
{
cout<<" ";
}
}
cout<<" ";
for(int j=0;j<7;j++)
{
if(j==test2)
{
cout<<"0"<<t22<<" ";
t22++;
test2++;
}else
{
cout<<" ";
}
}
cout<<endl<<endl;
int t3=1,t33=1;
int j1=t22;
for(int j=t2;j<=dy(year1,i+1);j++,t2++)
{
if(t3==8)
{
nb:
cout<<" ";
for(j1;j1<=dy(year1,i+2);j1++,t22++)
{
if(t33==8)
{
cout<<endl;
t33=1;
break;
}
if(j1<10)
{
cout<<"0"<<t22<<" ";
}else
{
cout<<t22<<" ";
}
t33++;
if(t22==dy(year1,i+2))
{
if(j==dy(year1,i+1)&&(t3!=8||rq(year1,i+1,t2)==6))
{
goto nb111;
}else
{
cout<<endl<<endl;
break;
}
}
if(j==dy(year1,i+1)&&(t22!=dy(year1,i+2))&&t33==8)
{
cout<<endl<<" ";
t2++;
t33=1;
continue;
}
}
cout<<endl;
t3=1;
}
if(j<10)
{
cout<<"0"<<t2<<" ";
}else if(j>=10)
{
cout<<t2<<" ";
}
t3++;
if(j==dy(year1,i+1))
{
for(int m=1;m<8-t3;m++)
{
cout<<" ";
}
if(t3!=8)
{
cout<<" ";
}
if(j1!=dy(year1,i+2))
{
goto nb;
}
}
}
nb111:
cout<<endl<<endl;
}
}else
{
int year1=1582;
char week1[8][10] = {"周日","周一","周二","周三","周四","周五","周六"};
char yue[20][20] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
for(int i=0;i<12;i+=2)
{
int ttt;
cout<<" "<<yue[i]<<" "<<yue[i+1]<<endl;
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<" ";
for(int j=0;j<7;j++)
{
cout<<week1[j]<<" ";
}
cout<<endl;
int test1=rq(year1,i+1,1),test2=rq(year1,i+2,1);
int t2=1,t22=1;
for(int j=0;j<7;j++)
{
if(j==test1)
{
cout<<"0"<<t2<<" ";
t2++;
test1++;
}else
{
cout<<" ";
}
}
cout<<" ";
for(int j=0;j<7;j++)
{
if(i+1==9&&j==5)
{
t22=15;
}
if(j==test2)
{
if(t22<10)
{
cout<<"0"<<t22<<" ";
}else
{
cout<<t22<<" ";
}
t22++;
test2++;
}else
{
cout<<" ";
}
}
cout<<endl<<endl;
int t3=1,t33=1;
int j1=t22;
for(int j=t2;j<=dy(year1,i+1);j++,t2++)
{
if(t3==8&&t22!=dy(year1,i+2))
{
nb44:
cout<<" ";
for(j1;j1<=dy(year1,i+2);j1++,t22++)
{
if(t33==8)
{
cout<<endl;
t33=1;
break;
}
if(j1<10)
{
cout<<"0"<<t22<<" ";
}else
{
cout<<t22<<" ";
}
t33++;
if(t22==dy(year1,i+2))
{
if(j==dy(year1,i+1)&&(t3!=8||rq(year1,i+1,t2)==6))
{
goto nb1;
}else
{
cout<<endl<<endl;
break;
}
}
if(j==dy(year1,i+1)&&(t22!=dy(year1,i+2))&&t33==8)
{
cout<<endl<<" ";
t2++;
t33=1;
continue;
}
}
cout<<endl;
t3=1;
}
if(i==8&&(t2==23||t2==30))
{
cout<<endl<<endl<<endl;
}
if(j<10)
{
cout<<"0"<<t2<<" ";
}else if(j>=10)
{
cout<<t2<<" ";
}
t3++;
if(j==dy(year1,i+1))
{
for(int m=1;m<8-t3;m++)
{
cout<<" ";
}
if(t3!=8)
{
cout<<" ";
}
if(j1!=dy(year1,i+2))
{
goto nb44;
}
}
}
nb1:
cout<<endl<<endl;
}
}
}else{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<"输入错误,请重新选择:";
goto wen2;
}
}else if(a=="4")
{
break;
}else
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<"输入错误,请重新选择:";
goto wen1;
}
wen:
cout<<"1.继续查询:"<<endl;
cout<<"2.退出"<<endl;
string b;
cin>>b;
if(b=="1")
{
continue;
}else if(b=="2")
{
break;
}else
{
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout<<"输入错误,请重新选择:"<<endl;
goto wen;
}
}
for(int i=1000;i>=0;i--)
{
cout<<endl;
}
cout << " ******** ******** "<< endl;
cout << " *********** ************ "<< endl;
cout << "************* *************" << endl;
cout << " ************************* "<< endl;
cout << " ******谢谢!!!******** "<< endl;
cout << " ******************** "<< endl;
cout << " ****************** "<< endl;
cout << " **************** "<< endl;
cout << " ************ "<< endl;
cout << " ******** "<< endl;
cout << " **** "<< endl;
cout << " 谢谢!!! "<< endl;
cout << " **** "<< endl;
cout << " ******** "<< endl;
cout << " ************ "<< endl;
cout << " **************** "<< endl;
cout << " ****************** "<< endl;
cout << " ******************** "<< endl;
cout << " *******谢谢!!!****** "<< endl;
cout << " ************************ "<< endl;
cout << " ************* ************ "<< endl;
cout << " *********** *********** "<< endl;
cout << " ******** ******** "<< endl;
return 0;
}