标答思路
2026-02-20 21:38:42
发布于:江苏
18阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N[12]={3,6,6,2,4,7,2,5,1,3,6,1};//枚举每月第一天的星期
const int M[12]={31,28,31,30,31,30,31,31,30,31,30,31};//枚举每月天数
int main(){
int n;cin>>n;int t=1;bool m=0;//T:计数变量,M:判断第一天是否已经输出
cout<<"MON TUE WED THU FRI SAT SUN"<<endl;//输出表头
for(int i=0;i<6;i++){
for(int j=0;j<7;j++){
if(j+1==N[n-1] && !m){cout<<" 1 ";m=1;t++;}//判断第一天输出时机
else if(m){printf("%3d",t);cout<<" ";t++;}
else cout<<" ";
if(t>M[n-1]){break;}//判断到达目标输出后跳出
}
cout<<endl;
if(t>M[n-1]){break;}//判断到达目标输出后跳出
}
return 0;
}
这里空空如也







有帮助,赞一个