• CCF-201509-2-日期计算


    问题描述

    试题编号: 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
    思路:

    分平闰年判断,开两个数组,天数逐次用数组去减,小于0的时候跳出来。




    源代码:

    <span style="font-size:18px;">#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<deque>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<string>
    #include<iomanip>
    #include<cstdlib>
    #include<cmath>
    #include<sstream>
    #include<ctime>
    using namespace std;
    
    int monthone[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int monthtwo[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    
    bool selectYear(int year)
    {
        bool flag;
        if(((year%4==0)&&(year%100!=0))||(year%400==0))
            flag=true;
        else
            flag=false;
        return flag;
    }
    
    int main()
    {
        int year;
        int day;
        int temp;
        int i=1;
        scanf("%d",&year);
        scanf("%d",&day);
        if(selectYear(year)==false)
        {
            while(day>0)
            {
                temp=day;
                day=day-monthone[i];
                i++;
            }
        }
        else if(selectYear(year)==true)
        {
            while(day>0)
            {
                temp=day;
                day=day-monthtwo[i];
                i++;
            }
        }
        printf("%d
    %d
    ",i-1,temp);
    	return 0;
    }
    </span>



  • 相关阅读:
    jquery判断元素是否可见隐藏
    jQuery的replaceWith()函数用法详解
    前端工作面试问题
    Windows下安装sass和compass失败的解决办法
    马尾图案之canvas的translate、scale、rotate的方法详解
    boost bimap
    boost multi index
    boost regex expression
    boost format
    boost lexical_cast
  • 原文地址:https://www.cnblogs.com/lemonbiscuit/p/7776075.html
Copyright © 2020-2023  润新知