• 蓝桥杯2015-省赛-C/C++-A组2题 星系炸弹


    在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。
    每个炸弹都可以设定多少天之后爆炸。
    比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。
    有一个贝塔炸弹,a年b月c日放置,定时为n天,请你计算它爆炸的准确日期。

    输入

    输入存在多组数据,每组数据输入一行,每一行输入四个正整数a,b,c,n
    输入保证日期在1000-01-01到2020-01-01之间,且日期合法。
    n不超过1000

    输出

    请填写该日期,格式为 yyyy-mm-dd  即4位年份2位月份2位日期。比如:2015-02-19
    请严格按照格式书写。不能出现其它文字或符号。

    样例输入 Copy

    2015 1 1 15
    2014 11 9 1000

    样例输出 Copy

    2015-01-16
    2017-08-05

    #include<iostream>
    #include<cstring>
    #include<iomanip>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    using namespace std;
    
    
    bool judge(int y)//判断是不是闰年 
    {
        if(y%4==0&&y%100!=0||y%400==0)
        return true;
        else
        return false;
    }
    int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
        int year,month,day;
        int n;
    while(    cin>>year>>month>>day>>n)
    {
    
        while(n)
        {
                if(judge(year))
              {
            mon[2]=29;
             }
             else
             mon[2]=28;
            if(day<=mon[month])
            day++;
            if(day>mon[month])
             {
             day=1;
             month++;
            }
            if(month>12)
            {
             year++;
             month=1;
           }
            n--;   
        }
        cout<<year<<"-";
        if(month<10)
        cout<<"0"<<month<<"-";
        else
        cout<<month<<"-";
        if(day<10)
        cout<<"0"<<day<<endl;
        else
        cout<<day<<endl;
      }
    }


  • 相关阅读:
    Webpack常用模块加载器Loader
    CSS动画 关键帧
    React 入门(6): 路由 React-Router
    React 入门(5): 引入JSX 研究JSX的createElement实现
    webpack标准模块 npm通用模块
    常用库的CDN引入
    使用codesandbox.io开启Web云开发
    css-loader + style-loader 模块化css
    React 入门(4): 单文件组件 CSS-Modules
    openldap主从数据同步-基于debain 9
  • 原文地址:https://www.cnblogs.com/h694879357/p/12234778.html
Copyright © 2020-2023  润新知