C++问题求帮写!!

问题遇到的现象和发生背景

img

img

用代码块功能插入代码,请勿粘贴截图

c++编译环境vs2017

#include<iostream>
using namespace std;
int panduan(int month, int year) {
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        return 31;
    else if (month == 4 || month == 6 || month == 9 || month == 11)
        return 30;
    else if (month == 2) {
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
            return 29;
        else
            return 28;
    }
}
int main() {
    int count[7] = { 0 };
    int n, i, j, day, d = 0, k;
    cin >> n;
    for (i = 1900; i <= 1900 + n - 1; i++) {
        for (j = 1; j <= 12; j++) {
            day = panduan(j, i);//循环1-7,d对应星期几
            for (k = 1; k <= day; k++) {
                d = d + 1;
                if (d == 8)
                    d = 1;
                if (k == 13)
                    count[d - 1]++;//13号时d是星期几 计数
            }
        }
    }
    cout << "" << count[0];
    cout << " " << count[1];
    cout << " " << count[2];
    cout << " " << count[3];
    cout << " " << count[4];
    cout << " " << count[5];
    cout << " " << count[6];
    return 0;
}



```c++
#include<bits/stdc++.h>
using namespace std;
int n,k=6;
int day[10];
int month[15];

void f()
{
    month[0]=31;
    month[1]=31;
    month[2]=28;
    month[3]=31;
    month[4]=30;
    month[5]=31;
    month[6]=30;
    month[7]=31;
    month[8]=31;
    month[9]=30;
    month[10]=31;
    month[11]=30;
}
int main()
{
    memset(day,0,sizeof(day));
    scanf("%d",&n);
    day[6]++;   
    f();
    for(int i=0;i<n;i++)
    {
        month[2]=28;
        if ( ((1900+i)%4==0 &&(1900+i)%100!=0) ||(1900+i)%400==0)
        {
            month[2]=29;    
        }
        for(int j=1;j<=12;j++)
        {
                if(i==0 && j==1)    continue;
                k=(k+month[j-1]%7)%7;
                if(k==0)    k=7;
                day[k]++;
        }   
    }
    for(int i=6;i<=7;i++)
        cout<<day[i]<<" ";
    for(int i=1;i<=5;i++)
        cout<<day[i]<<" ";   
    return 0;
} 

```

#include <iostream>
#include <string>
#include <map>            
using namespace std;
int main()
{
    int n;         //total years
    cin >> n;
    int pn[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int rn[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    map<int, int> week;
    long days = 13;
    for (int i = 1900; i < 1900 + n; i++)
    {
        if (i%400==0)
        {
            for (int j = 0; j < 12;j++)
            {
                week[(days - 1) % 7 + 1] += 1;
                days += rn[j];
            }
        }

        if (i%100!=0&&i%4==0)
        {
            for (int j = 0; j < 12;j++)
            {
                week[(days - 1) % 7 + 1] += 1;
                days += rn[j];
            }
        }

        if ((i%100==0&&i%400!=0)||i%4!=0)
        {
            for (int j = 0; j < 12;j++)
            {
                week[(days - 1) % 7 + 1] += 1;
                days += pn[j];
            }
        }


    }
    cout << week[6] << " " << week[7] << " " << week[1] << " ";
    cout << week[2] << " " << week[3] << " " << week[4] << " " << week[5] << endl;

    return 0;
}

补充代码?那么已有代码呢?