#include #include using namespace std; int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int b[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 闰年 int days = 0; //共多少天 int rows = 0; //共多少行 bool f(int n) // n是不是闰年 { if ((n % 4 == 0 && n % 100 != 0) || n % 100 == 0) return true; else return false; } void print(int t[]) //打印那一年 { for (int i = 0; i < 12; i++) { for (int j = 1; j <= t[i]; j++) { cout << j << " "; days++; if (days % 7 == 0) // 7天一礼拜 { cout << endl; rows++; } } } } int main() { int start = 1901; int end = 2000; for (int i = start; i <= end; i++) { if (f(i) == true) //是闰年,按b数组打印 print(b); else //不是,按a数组打印 print(a); } cout << "rows is " << endl; cout << rows << endl; return 0; }