蓝桥杯日期问题

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
		System.out.println((int)Math.pow(20, 22)%7+6);
        scan.close();
    }
}

import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
   public static void main(String[] args) {
        int countyeah=0,yeah=1777,day=0,month=4;
        String lingy="",lingr="";
        for (int i = 0; i < 8113/366; i++) {
            if (Run(++yeah)) {
                countyeah++;
            }
        }
        day =8113- (countyeah*366+(8113/365-countyeah)*365);
        while (day>=30) {
            if (month>=13) {
                month=month-12;
            }
            switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                month++;
                day-=31;
            case 4:
            case 6:
            case 9:
            case 11:
                month++;
                day-=30;
                break;
            case 2:
                if (Run(yeah)) {
                    month++;
                    day-=29;
                }
                else {
                    month++;
                    day-=28;
                }
            }
        }
        if (day>0) {
            month++;
        }
        else {
            day=29+day;
        }
        if (month<10) {
            lingy="0"+month;
        }
        else {
            lingy=month+"";
        }
        if (day<10) {
            lingr="0"+day;
        }
        else {
            lingr=day+"";
        }
        System.out.println(yeah+"-"+lingy+"-"+lingr);
    }
    
    public static boolean Run(int yeah) {
        return ((yeah%4==0&&yeah%100!=0)||yeah%400==0)?true:false;
    }
}

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String date1 = scan.nextLine();
        String date2 = scan.nextLine();
        DateFormat format = new SimpleDateFormat("yyMMdd");
        Date enDate = format.parse(date2);
        Date start = format.parse(date1);
        long e = enDate.getTime();
        long s = start.getTime();
        System.out.println((e-s)/(60*60*24*1000)+1);
    }
}

java计算多少天后的日期

    /**
     *  计算多少天后的日期
     * @param date   手动输入日期
     * @param days   多少天后
     * @return
     * @throws ParseException
     */
    public static String addDate(String date,int days) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = format.parse(date);
        calendar.setTime(parse);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        // days  多少天后的日期
        int newDay = day+days;
        calendar.set(Calendar.YEAR,year);
        calendar.set(Calendar.MONTH,month);
        calendar.set(Calendar.DAY_OF_MONTH,newDay);
        return format.format(calendar.getTime());
    }

import java.util.Arrays;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
	static int cnt = 0;
	static int[]month = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        for (int i = 19000101; i <= 99991231; i++) {
			if (check(i)&&calc(i)&&Check(i)) {
				cnt++;
			}
		}
        System.out.println(cnt);
        scan.close();
    }
    private static boolean Check(int n) {
    	String s = n+"";
    	n = n/10000;
    	int m = Integer.parseInt(s.substring(4, 6));
    	if (!(n%4==0&&n%100!=0||n%400==0)) {//如果不是闰年 2月没有29天
    		if (Integer.parseInt(s.substring(6, 8))==29&&m==2) {
				return false;
			}
		}
    	return true;
	}
    private static boolean check(int n) {
    	String s = n+"";
    	int day =Integer.parseInt(s.substring(6, 8));
    	int m = Integer.parseInt(s.substring(4, 6));
    	if (Integer.parseInt(s.substring(4, 6))>12||Integer.parseInt(s.substring(4, 6))==0) {
    			return false;
		}
    	if (month[m]<day||day==0) {
    		return false;
    	}
    	return true;
	}
    private static boolean calc(int n) {
    	String s = n+"";
    	int a = sum(Integer.parseInt(s.substring(0, 4)));
    	int b = sum(Integer.parseInt(s.substring(4, 6)));
    	int c = sum(Integer.parseInt(s.substring(6, 8)));
    	if (a==b+c) {
			return true;
		}
    	return false;
	}
    private static int sum(int n) {
    	int Sum = 0;
		while (n>0) {
			Sum+=n%10;
			n/=10;
		}
		return Sum;
	}
}

相关推荐

  1. 日期问题纯暴力)

    2024-04-07 19:24:01       40 阅读
  2. Acwing2024日期问题

    2024-04-07 19:24:01       36 阅读
  3. C/C++日期问题

    2024-04-07 19:24:01       40 阅读
  4. 】(完全日期

    2024-04-07 19:24:01       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-07 19:24:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-07 19:24:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-07 19:24:01       82 阅读
  4. Python语言-面向对象

    2024-04-07 19:24:01       91 阅读

热门阅读

  1. leetcode热题100.数组中的第k大的元素

    2024-04-07 19:24:01       38 阅读
  2. [leetcode] 66. 加一

    2024-04-07 19:24:01       34 阅读
  3. GPU的了解

    2024-04-07 19:24:01       46 阅读
  4. Redis实现网站访问人数统计

    2024-04-07 19:24:01       42 阅读
  5. 设计模式:观察者模式

    2024-04-07 19:24:01       43 阅读
  6. 全量知识系统 设计和实现的切入点探讨 (Q&A)

    2024-04-07 19:24:01       36 阅读
  7. 数据库面试题之Mysql

    2024-04-07 19:24:01       37 阅读
  8. Django--方法

    2024-04-07 19:24:01       39 阅读
  9. Vue 【vite使用alias】

    2024-04-07 19:24:01       38 阅读