1 条题解

  • 0
    @ 2026-2-10 16:08:40

    C :

    #include<stdio.h>
    int main()
    {
    	int a,b,c,t;
    	t=0;
    	scanf("%d-%d-%d",&a,&b,&c);
    	if(b==1)
    	{
           t=0;
    	}
    	else if(b==2)
    	{
    	   t=31;
    	}
    	else if(b==3)
    	{
    	   t=31+28; 	
    	}
    	else if(b==4)
    	{
    	   t=31+28+31; 	
    	}
    	else if(b==5)
    	{
    	   t=31+28+31+30; 	
    	}
    	else if(b==6)
    	{
    	   t=31+28+31+30+31; 	
    	}
    	else if(b==7)
    	{
    	   t=31+28+31+30+31+30; 	
    	}else if(b==8)
    	{
    	   t=31+28+31+30+31+30+31; 	
    	}else if(b==9)
    	{
    	   t=31+28+31+30+31+30+31+31; 	
    	}else if(b==10)
    	{
    	   t=31+28+31+30+31+30+31+31+30; 	
    	}else if(b==11)
    	{
    	   t=31+28+31+30+31+30+31+31+30+31; 	
    	}
    	else if(b==12)
    	{
    	   t=31+28+31+30+31+30+31+31+30+31+30; 	
    	}
        t=t+c;
    	if(a%4==0&&a%100!=0||a%400==0)
    	{
    		if(b>2)
    		{
    			t = t+1; 
    		}
    	 }
    	 printf("%d\n",t);
    	  
    }
    
    

    C++ :

    
    #include<stdio.h>
    int main()
    {
        int a,b,c,t;
        t=0;
        scanf("%d-%d-%d",&a,&b,&c);
        if(b==1)
        {
            t=0;
        }
        else if(b==2)
        {
            t=31;
        }
        else if(b==3)
        {
            t=31+28;
        }
        else if(b==4)
        {
            t=31+28+31;
        }
        else if(b==5)
        {
            t=31+28+31+30;
        }
        else if(b==6)
        {
            t=31+28+31+30+31;
        }
        else if(b==7)
        {
            t=31+28+31+30+31+30;
        }
        else if(b==8)
        {
            t=31+28+31+30+31+30+31;
        }
        else if(b==9)
        {
            t=31+28+31+30+31+30+31+31;
        }
        else if(b==10)
        {
            t=31+28+31+30+31+30+31+31+30;
        }
        else if(b==11)
        {
            t=31+28+31+30+31+30+31+31+30+31;
        }
        else if(b==12)
        {
            t=31+28+31+30+31+30+31+31+30+31+30;
        }
        t=t+c;
        if(a%4==0&&a%100!=0||a%400==0)
        {
            if (b > 2)
            {
              t = t+1;  
            }
             
        }
        printf("%d\n",t);
    }
         
     
     
    

    Java :

    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            // 解析输入的日期
            String[] parts = input.split("-");
            int year = Integer.parseInt(parts[0]);
            int month = Integer.parseInt(parts[1]);
            int day = Integer.parseInt(parts[2]);
    
            // 计算当天是这一年的第几天
            int dayOfYear = day + daysInPreviousMonths(month, year);
    
            // 输出结果
            System.out.println(dayOfYear);
        }
    
        // 计算指定月份之前的所有天数
        private static int daysInPreviousMonths(int month, int year) {
            int[] daysInMonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            int days = 0;
    
            // 判断是否为闰年
            if (isLeapYear(year)) {
                daysInMonth[2] = 29;
            }
    
            for (int i = 1; i < month; i++) {
                days += daysInMonth[i];
            }
            return days;
        }
    
        // 判断是否为闰年
        private static boolean isLeapYear(int year) {
            return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
        }
    }
    

    Python :

    # coding=utf-8
    #python2
    m = [31,28,31,30,31,30,31,31,30,31,30,31]
    a,b,c = map(int,raw_input().split('-'))
    s = 0
    if a%4==0 and a%100!=0 or a%400==0:
        m[1] = 29
    for i in range(b-1):
        s += m[i]
    s += c
    print(s)
    

    C# :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp2
    {
        internal class Program
        {
            static void Main()
            {
                int r = 0;
                int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
                string[] O  = Console.ReadLine().Split('-');
                int year =Convert.ToInt16( O[0]);
                int m = Convert.ToInt16(O[1]);
                int d = Convert.ToInt16(O[2]);
                if ( (year%4==0 && year%100!=0 )|| year%400==0 ) {
                    days[1] += 1;
                    for (int i = 0; i < m-1; i++) {
                    r += days[i];
                    }
                   
                    
                }
                else
                {
                    for (int i = 0; i < m - 1; i++)
                    {
                        r += days[i];
                    }
                }
                r += d;
                Console.WriteLine(r);
                Console.ReadKey();
         
            }
        }
    }
    
    • 1

    信息

    ID
    31
    时间
    1000ms
    内存
    128MiB
    难度
    3
    标签
    递交数
    0
    已通过
    0
    上传者