输入年月日判断是这一年的哪一天

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Write("请输入年");
                int year = int.Parse(Console.ReadLine());
                Console.Write("请输入月");
                int mouth = int.Parse(Console.ReadLine());
                Console.Write("请输入日");
                int day = int.Parse(Console.ReadLine());
                if (mouth == 1 &&( year > 1795 && year < 9999) &&( day > 0 && day <= 31))
                {
                    Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", day);
                }
                else if ((year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) &&( year > 1795 && year < 9999 )&&( mouth > 0 && mouth <= 12) && (day > 0 && day <= 31))
                {
                    if (mouth == 2 && day <= 29)
                    {
                        int m = 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 3 && day <= 31)
                    {
                        int m = 31 + 29 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 4 && day <= 30)
                    {
                        int m = 31 + 29 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 5 && day <= 31)
                    {
                        int m = 31 + 29 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 6 && day <= 30)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 7 && day <= 31)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 8 && day <= 30)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 9 && day <= 31)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 10 && day <= 31)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 11 && day <= 30)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 12 && day <= 31)
                    {
                        int m = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                }
                else if ((year > 1795 && year < 9999) &&( mouth > 0 && mouth <= 12) && (day > 0 && day <= 31))
                {
                    if (mouth == 2 && day <= 28)
                    {
                        int m = 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 3 && day <= 31)
                    {
                        int m = 31 + 28 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 4 && day <= 30)
                    {
                        int m = 31 + 28 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 5 && day <= 31)
                    {
                        int m = 31 + 28 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 6 && day <= 30)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 7 && day <= 31)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 8 && day <= 30)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 9 && day <= 31)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 10 && day <= 31)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 11 && day <= 30)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                    else if (mouth == 12 && day <= 31)
                    {
                        int m = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
                        Console.WriteLine(year.ToString() + "年" + mouth.ToString() + "月" + day.ToString() + "日" + "是这一年的第{0}天", m);
                    }
                }
                else
                {
                    Console.WriteLine("请输入正确的年月日");
                }
                Console.ReadLine();
            }
        }
    }
}
时间: 2024-11-05 21:37:58

输入年月日判断是这一年的哪一天的相关文章

输入年月日,判断是该年的第几天,还可以进一步判断从1年开始的第几天

//输入年月日,判断是该年的第几天,还可以进一步判断从1年开始的第几天 #include<iostream> using namespace std; int main() { int Day(int x,int y,int r); int Calculate_1(int x,int y,int r); int Calculate_2(int n); int n,y,r;/*****************************************************年,月,日,很明

输入年月日 判断是第几天(判断闰年)

import java.util.Scanner; class TestYear  { public static void main(String[] args)  { Scanner s= new Scanner(System.in); System.out.println("请输入年份:"); int year=s.nextInt(); System.out.println("请输入月份:"); int month=s.nextInt(); System.ou

C#习题之输入年月日判断是当年第几天

输入年月日判断是当年第几天

年月日判断并输出第多少天

方法一: while (true) { Console.Write("输入年:"); int year = int.Parse(Console.ReadLine()); Console.Write("输入月:"); int month = int.Parse(Console.ReadLine()); Console.Write("输入日:"); int day = int.Parse(Console.ReadLine()); bool isok

30.输入年月日,判断它是该年的第多少天

(1)运用swicth语句 #include<iostream> using namespace std; int main() { int y,m,d; int d1; int sum=0,sum1=0; cout<<"please input year,month,day: "<<endl; cin>>y>>m>>d; if(((y%4==0)&&(y%100!=0))||(y%400==0))

Practice:输入年月日,判断为一年的第几天

#-*- coding:utf-8 -*-'''Created on 2015-6-7# 输入年月日,判断为一年的第几天@author: AdministrInputator'''# strInput = '150223'# a = int(strInput[-2:])# print(a)def leapYear(year): # 判断平闰年,由于输入年份只有两位数,‘00’~‘69’转换为2000~2069,‘70’~’99‘转换为1970~1999 if year < 70: year +=

编程题:用函数实现,用户输入年月日,来计算出该日期为当年第几天?

#include<stdio.h> /*函数is_leap_year()的返回值是判断该年是否闰年*/ int is_leap_year(int year) { int leap; if(year%4==0&&year%100!=0||year%400==0) leap=1; else leap=0; return leap; } /*函数len_of_month()的返回值为某年year的某月month的天数*/ int len_of_month(int year,int m

输入年月日计算是星期几

偶然的机会看到了一个计算星期几的算法,感觉很怪异并且很有意思就记录一下,也与大家共勉.自己写的代码有些瑕疵,但重点是计算星期的算法值得思索. 问题:输入年月日计算是星期几? 代码如下: #include <stdio.h>int getWeek(int year, int month, int day){ int aWeek[12] = {0,3,2,5,0,3,5,1,4,6,2,4}; int week = 0; int temp = 0; if(year < 1 || month