Daily brush questions (100)
Gauss Diary
Topic overview
The great mathematician Gauss has a good habit: keep a diary anyway.
There is a difference in his diary. He never noted the year, month, and day, but instead used an integer instead. For example, after 4210,
people knew that the integer was the date, which said that day was the day after Gauss was born. day. This may also be a good habit. It reminds the owner all the time: One day has passed, how much time can be used to waste?
Gauss was born: April 30, 1777.
In the diary of an important theorem discovered by Gauss, it is marked: 5343, so it can be calculated that the day is: December 15, 1791.
The diary on the day when Gauss received his doctorate is marked: 8113
, please calculate the year, month and day when Gauss received his doctorate.
Output format
The format for submitting answers is: yyyy-mm-dd, for example: 1980-03-21
Please follow the format strictly and submit your answers through the browser.
Note: Only submit this date, do not write other additional content, such as: descriptive text.
Method 1: Moderate C++
#include<bits/stdc++.h>
using namespace std;
//平年and闰年
int month[13][2] = {
{
0, 0}, {
31, 31}, {
28, 29}, {
31, 31}, {
30, 30}, {
31, 31}, {
30, 30}, {
31, 31}, {
31, 31}, {
30, 30}, {
31, 31}, {
30, 30}, {
31, 31}};
bool isLeap(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main()
{
int days;
cin >> days;
int y1 = 1777;
int m1 = 4;
int d1 = 30;
while(days)
{
d1++;
if(d1 == month[m1][isLeap(y1)] + 1)
{
m1++;
d1 = 1;
}
if(m1 == 13)
{
y1++;
m1 = 1;
}
days--;
}
cout << y1 << m1 << d1 << endl;
return 0;
}
Through the example, we can see that April 30, 1777 is to be included,
so it is subtracted by 1 on the basis of 1799717.
So the answer is 1799-07-17
Method 2: Excel Method
Partial screenshot