zoukankan      html  css  js  c++  java
  • c++计算改日是本年的第几天

    任务描述:

    定义一个结构体变量(包括年、月、日),编写程序,要求输入年、月、日,程序能计算并输出该日在本年中是第几天。注意闰年问题。

    测试输入:

    2000 12 20

    预期输出:

    12/20 is the 355th day in 2000

    程序源码:

    #include <iostream>
    using namespace std;
    struct
    { 
    int year;
    int month;
    int day;
    }date;
    
    int main()
    {
    int days;
    cin>>date.year>>date.month>>date.day;
    
    // 请在此添加代码
        /********** Begin *********/
        days=0;    
        switch(date.month)
        {
            case 12: days=days+30;
            case 11: days=days+31;
            case 10: days=days+30;
            case 9: days=days+31;
            case 8: days=days+31;
            case 7: days=days+30;
            case 6: days=days+31;
            case 5: days=days+30;
            case 4: days=days+31;
            case 3: if(date.year%4==0 && date.year%100!=0 ||date.year%400==0)
                        days=days+29;
                    else days=days+28;
            case 2: days=days+31;
            case 1: days=days+date.day;
            default :break;
        }
        
        
        /********** End **********/
    
    cout<<date.month<<"/"<<date.day<<" is the "<<days<<"th day in "<<date.year<<"."<<endl;
    return 0;
    }
  • 相关阅读:
    Codeforces-859C Pie Rules(dp)
    Codeforces-550D Regular Bridge
    Codeforces-534D Handshakes
    抽象类
    内部类
    接口
    初始化
    this 和super
    数据库测试的测试点
    数据库测试的主要内容
  • 原文地址:https://www.cnblogs.com/junfblog/p/12705624.html
Copyright © 2011-2022 走看看