试题编号: | 201509-2 |
试题名称: | 日期计算 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 给定一个年份y和一个整数d,问这一年的第d天是几月几日? 输入格式 输入的第一行包含一个整数y,表示年份,年份在1900到2015之间(包含1900和2015)。 输出格式 输出两行,每行一个整数,分别表示答案的月份和日期。 样例输入 2015 样例输出 3 样例输入 2000 样例输出 2 |
#include
using namespace std;
int Is_run(int x) //判断闰年
{
if((x % 100 != 0 && x % 4 == 0 )|| x % 400 == 0)
return 1;
else
return 0;
}
int day[12][2]={{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}}; //第一列时平年每个月的天数,第二列时闰年每个月的天数
int main()
{
int y,d;
cin>>y>>d;
int a=Is_run(y);
if(a==1) //若是闰年
{
int i=0,temp=0;
while((temp+day[i][1])