问题描述
试题编号: | 201509-2 |
试题名称: | 日期计算 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 给定一个年份y和一个整数d,问这一年的第d天是几月几日? 输入格式 输入的第一行包含一个整数y,表示年份,年份在1900到2015之间(包含1900和2015)。 输出格式 输出两行,每行一个整数,分别表示答案的月份和日期。 样例输入 2015 样例输出 3 样例输入 2000 样例输出 2 |
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int month[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int year,sum;
scanf("%d%d",&year,&sum);
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
month[2]++;
int i;
for(i=1; i<=12; i++)
{
if(sum >= month[i])
{
sum -= month[i];
if(sum == 0)
{
sum = month[i];
break;
}
}
else
break;
}
printf("%d\n",i);
printf("%d\n",sum);
return 0;
}