Foreword:
21. Regardless of whether you can enter the retest or not, record the garbage code written on the road. I originally gnawed on "Algorithm Notes", but I felt too much to do it, so I changed it to the Kingway Computer Test Guide.
Title description:
Design a program to calculate what date is after a date plus a few days.
enter
Enter the first line to indicate the number of samples m, and the four integers in each line of the next m lines to indicate the year, month, and day, and the number of days accumulated.
Output description:
Output m lines, each line is output according to the number of yyyy-mm-dd.
answer:
#include <stdio.h>
const int daytab[2][13] = {
{
0,31,28,31,30,31,30,31,31,30,31,30,31},
{
0,31,29,31,30,31,30,31,31,30,31,30,31}
};
bool isleapyear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
}
int main()
{
int m, year, mon, day, date;
scanf("%d", &m);
for (int j = 0; j < m; j++) {
scanf("%d%d%d%d", &year, &mon, &day, &date);
date += day;
for (int i = mon; i < 13; i++)
{
if ((date - daytab[isleapyear(year)][i]) > 0)
date -= daytab[isleapyear(year)][i];
else break;
mon++;
if (mon == 13) {
mon = 1;
i = 1;
year++;
}
}
day = date;
printf("%04d-%02d-%02d\n", year, mon, day);
}
return 0;
}
The OJ on Niuke.com is not all right, I don't know why, and I don't understand what this use case means. The date has been pushed forward.
Probably something went wrong with the problem.