zoukankan      html  css  js  c++  java
  • CCF-201509-2-日期计算

     1 // ccf日期计算.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 
     5 #include<iostream>
     6 using namespace std;
     7 int day[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
     8 bool isleap(int year) {
     9     if (year % 4 == 0 & year % 100 != 0 || year % 400 == 0) {
    10         return true;
    11     }
    12     return false;
    13 }
    14 
    15 int main()
    16 {
    17     int year,d;
    18     cin >> year >> d;
    19     if (isleap(year)) {
    20         day[2] = 29;
    21     }
    22     else {
    23         day[2] = 28;
    24     }
    25     int mm = 1;
    26     for (int i = 1;i <= 12;i++) {
    27         if (d <= day[1]) {
    28             break;
    29         }
    30         d -= day[i];
    31         mm++;
    32     }
    33     cout << mm<<endl << d << endl;
    34     return 0;
    35 }
    试题编号: 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
    雄关不惧 成败自含香
  • 相关阅读:
    WordCount
    vs2013安装及测试
    阅读程序,回答问题
    补作业:随机生成二元四则运算
    第一次合作
    漫漫“码农”路
    我的进度条
    Believe
    软件工程个人总结
    结队作业——电梯调度程序
  • 原文地址:https://www.cnblogs.com/cswangchen/p/7531382.html
Copyright © 2011-2022 走看看