P9177 [COCI2022-2023#5] Kalendar 题解

· · 题解

首先上下两行格式是固定的,直接输出即可。

其次看中间行:

#include<iostream>
using namespace std;
int n,x,d;
int main(){
    cin>>n>>x;
    puts("+---------------------+");
    d-=(x-2);//保证第一天的位置是正确的
    for(int i=1;;i++){
        cout<<"|";
            for(int j=1;j<=7;j++){
            if(d<=0||d>n) cout<<"...";
            else if(d>0&&d<10) cout<<".."<<d;
            else cout<<"."<<d;
            d++;
        }
        cout<<"|"<<endl;
        if(d>n) break;
    }
    puts("+---------------------+");
}