CCF 日期计算

来源:互联网 发布:vmware linux nat模式 编辑:程序博客网 时间:2024/06/05 20:37

问题描述
试题编号:201509-2试题名称:日期计算时间限制:1.0s内存限制:256.0MB问题描述:
问题描述
  给定一个年份y和一个整数d,问这一年的第d天是几月几日?
  注意闰年的2月有29天。满足下面条件之一的是闰年:
  1) 年份是4的整数倍,而且不是100的整数倍;
  2) 年份是400的整数倍。
输入格式
  输入的第一行包含一个整数y,表示年份,年份在1900到2015之间(包含1900和2015)。
  输入的第二行包含一个整数d,d在1至365之间。
输出格式
  输出两行,每行一个整数,分别表示答案的月份和日期。
样例输入
2015
80
样例输出
3
21
样例输入
2000
40
样例输出
2
9

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;//1061109567typedef long long LL;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using 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;}


0 0
原创粉丝点击