问题标题: 怎么输出日历?

0
0
已解决
于行衍
于行衍
初级守护
初级守护

#include<bits/stdc++.h>
using namespace std;
int y,m,d,h;
int r[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int p[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int leap(int y){
    int f,h,fh;
    f=y%4;
    h=y%100;
    fh=y%400;
    if(f==0&&h==0&&fh==0){
        return 1;
    }else if(f==0&&h!=0&&fh!=0){
        return 1;    
    }else{
        return 0;
    }
}
int qiuhe(int y,int m,int d,int r[],int p[]){
    int i,sum=0;
    for(i=1900;i<=y;i++){
        int m;
        m=leap(i);
        if(m==1){
            sum+=366;
        }else{
            sum+=365;
        }
    }
    for(i=0;i<=m;i++){
        if(leap(y)==1){
            sum+=r[i];
        }else{
            sum+=p[i];
        }
    }
    return sum;
}
void muban(){
    char weekday[7][10] = {"Monday\t","Tuesday\t","Wednesday\t","Thursday\t","Friday\t","Saturday\t","Sunday"};
    int i;
    for(i=0;i<7;i++){
        cout<<weekday[i]<<endl;
    }
}
void shibiePrint(int sum,int y,int m){
    int ys,t,i;
    ys=sum%7;
    for(i=0;i<=ys;i++){
        cout<<"\t";
    }
    t=7-ys;
    if(leap(y)==1){
        for(i=1;i<=r[m=1];i++){
            cout<<i<<"\t";
            if(i==t||(i-t)%7==0){
                cout<<endl;
            }
        }
        cout<<endl;
    }else{
        for(i=1;i<=p[m-1];i++){
            cout<<i<<"\t";
            if(i==t||(i-t)%7==0){
                cout<<endl;
            }
        }
        cout<<endl;
    }
}
int main(){
    cin>>y>>m>>d;
    h=qiuhe(y,m,d,r,p);
    cout<<"\t\t\t"<<y<<"year"<<m<<"month\n\n";
    muban();
    shibiePrint(h,y,m);
    return 0;
}

 

 

第四十行:char weekday[7][10] = {"Monday\t","Tuesday\t","Wednesday\t","Thursday\t","Friday\t","Saturday\t","Sunday"};为啥错?


0
已采纳
王梓轩
王梓轩
资深光能
资深光能
#include<endpointvolume.h>
#include<bits/stdc++.h>
#include<mmdeviceapi.h>
#include<audioclient.h>
#include<windows.h>
#include<mmsystem.h>
#include<locale.h>
#include<direct.h>
#include<conio.h>
#include<tchar.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#pragma comment(lib,"winmm.lib")
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
void guangbiao()
{
    CONSOLE_CURSOR_INFO x={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&x);
}
int xingqi(int year,int month,int day)
{
    if(month==1||month==2)month+=12,year--;
    return (day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
}
void shuchuyue(int hang)
{
    if(hang==1)cout<<"      January               February               March        ";
    if(hang==2)cout<<"       April                  May                   June        ";
    if(hang==3)cout<<"        July                 August              September      ";
    if(hang==4)cout<<"      October               November              December      ";
    cout<<"\nSu Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa\n";
}
bool runnian(int year)
{
    return year%4==0&&year%100!=0||year%400==0;
}
int tianshu(int year,int m)
{
    if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)return 31;
    else if(m==4||m==6||m==9||m==11)return 30;
    else if(runnian(year))return 29;
    else return 28;
}
void shuchuri(int year,int hang)
{
    int a1=xingqi(year,(hang-1)*3+1,1),a2=xingqi(year,(hang-1)*3+2,1),a3=xingqi(year,(hang-1)*3+3,1);
    int b1=2,b2=2,b3=2;
    int x1=(a1+1)%7+1,x2=(a2+1)%7+1,x3=(a3+1)%7+1;
    cout<<setw(x1*3-1)<<1<<" ";
    a1=x1;
    for(; a1<=6; b1++)
    {
        a1++;
        cout<<setw(2)<<b1<<" ";
    }
    cout<<" "<<setw(x2*3-1)<<1<<" ";
    a2=x2;
    for(; a2<=6; b2++)
    {
        a2++;
        cout<<setw(2)<<b2<<" ";
    }
    cout<<" "<<setw(x3*3-1)<<1<<" ";
    a3=x3;
    for(; a3<=6; b3++)
    {
        a3++;
        cout<<setw(2)<<b3<<" ";
    }
    cout<<endl;
    for(int i=2; i<=6; i++)
    {
        if(b1<=tianshu(year,(hang-1)*3+1))cout<<setw(2)<<b1++<<" ",a1=1;
        else cout<<"   ",b1++,a1=1;
        for(; a1<=6; b1++)
        {
            a1++;
            if(b1<=tianshu(year,(hang-1)*3+1))cout<<setw(2)<<b1<<" ";
            else cout<<"   ";
        }
        cout<<" ";
        if(b2<=tianshu(year,(hang-1)*3+2))cout<<setw(2)<<b2++<<" ",a2=1;
        else cout<<"   ",b2++,a2=1;
        for(; a2<=6; b2++)
        {
            a2++;
            if(b2<=tianshu(year,(hang-1)*3+2))cout<<setw(2)<<b2<<" ";
            else cout<<"   ";
        }
        cout<<" ";
        if(b3<=tianshu(year,(hang-1)*3+3))cout<<setw(2)<<b3++<<" ",a3=1;
        else cout<<"   ",b3++,a3=1;
        for(; a3<=6; b3++)
        {
            a3++;
            if(b3<=tianshu(year,(hang-1)*3+3))cout<<setw(2)<<b3<<" ";
            else cout<<"   ";
        }
        cout<<'\n';
    }
}
int setfont(int x,int y)
{
    HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_FONT_INFOEX cfi;
    GetCurrentConsoleFontEx(hout,FALSE,&cfi);
    cfi.cbSize=sizeof(cfi);
    cfi.nFont=0;
    cfi.dwFontSize.X=x;
    cfi.dwFontSize.Y=y;
    cfi.FontFamily=FF_DONTCARE;
    cfi.FontWeight=400;
    wcscpy(cfi.FaceName,L"NSimSun");
    return SetCurrentConsoleFontEx(hout,TRUE,&cfi);
}
void gotoxy(int x,int y)
{
    COORD c;
    c.X=x;
    c.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
void rili(int year)
{
    system("cls");
    cout<<"                              "<<year<<endl<<endl;
    for(int i=1; i<=4; i++)
    {
        shuchuyue(i);
        shuchuri(year,i);
    }
}
int main()
{
    guangbiao();
    system("color 70"); 
    ShowWindow(GetForegroundWindow(),SW_MAXIMIZE);
    setfont(12,24);
    int year;
    while(1)
    {
        system("cls");
        cout<<"请输入年份:\n";
        cin>>year;
        while(!(year>0&&year<10000))
        {
            system("cls");
            cout<<"错误!(范围1~9999)\n";
            cin>>year;
        }
        rili(year);
        getch();
    }
}

日历程序

0
Kevin
Kevin
中级守护
中级守护

很简单,用模拟和setw就行

0
我要回答