一枚渣子


私信TA

用户名:uq_44501180482

访问量:14826

签 名:

笨蛋

等  级
排  名 24
经  验 15995
参赛次数 1
文章发表 238
年  龄 0
在职情况 在职
学  校 河南科技大学
专  业

  自我简介:

渣子

TA的其他文章

////////////////////////////////////

第一种方法
////////////////////////////////////

import java.time.LocalDate;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		  
	Scanner sc=new Scanner(System.in);
         while(sc.hasNext()){
	  int y=sc.nextInt();
          int m=sc.nextInt();
          int d=sc.nextInt();
	     LocalDate begin=LocalDate.of(y,m,d);
	     LocalDate end=LocalDate.of(y+40,m,d);
	     int days=0;
	     while(!begin.isAfter(end)){
	    	 begin=begin.plusDays(1);
	    	 days++;
	    	 if(days==10000){ 
	    		 String[]s=begin.toString().split("-");
	    		 System.out.printf("%s-%d-%d\n",s[0],Integer.parseInt(s[1]),Integer.parseInt(s[2]));  
	    		 break;
	    	}
	      }
	    }
	 }
	}

	

////////////////////////////////////

第二种方法
////////////////////////////////////


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int Y=sc.nextInt();
			int M=sc.nextInt();
			int D=sc.nextInt();
			int sum=0;
			switch(M){
			case 1:case 3:case 5:case 7:case 8:case 10:case 12: sum+=31-D;break;
			case 4:case 6:case 9:case 11:sum+=30-D;break;
			case 2:if(isrun(Y)) sum+=29-D; else sum+=28-D;break;
			}
			for (int i=M+1; i <=12; i++) {
				switch(i){
				case 1:case 3:case 5:case 7:case 8:case 10:case 12: sum+=31;break;
				case 4:case 6:case 9:case 11:sum+=30;break;
				case 2:if(isrun(Y)) sum+=29;
				else sum+=28;break;
				}
			}
            int gety=0; int getm=0;int getd=0; boolean notfull=true;
			for (int i = Y+1; i <=3000; i++){
				gety=i;
				if(isrun(i)){					
					if(sum+366<10000) sum+=366;
					else if(sum+366==10000){ sum+=366;getm=12;getd=31; notfull=false;break;}
					else break;
				}
				else{ if(sum+365<10000) sum+=365;
				else if(sum+365==10000){ sum+=365;getm=12;getd=31;notfull=false;break; }
				else break;
				}
			}
			if(notfull){
			for (int i=1; i<=12; i++) {
				if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
					if(sum+31<10000){sum+=31;}
					else if(sum+31==10000){sum+=31;getd=31;getm=i;break;}
					else{ getd=10000-sum;getm=i; break;}
				}
				if(i==4||i==6||i==9||i==11){
					if(sum+30<10000){sum+=30;}
					else if(sum+30==10000){sum+=30;getd=30;getm=i;break;}
					else{ getd=10000-sum;getm=i;break;}
				}
				if(i==2){
					if(isrun(gety)){
						if(sum+29<10000){sum+=29;}
						else if(sum+29==10000){sum+=29;getd=29;getm=i;break;}
						else{ getd=10000-sum;getm=i;break;}
					}
					else{
						if(sum+28<10000){sum+=28;}
						else if(sum+28==10000){sum+=28;getd=28;getm=i;break;}
						else{ getd=10000-sum;getm=i;break;}
					}
				}
			}
		}
       System.out.println(gety+"-"+getm+"-"+getd);
	  }	
	}
	public static boolean isrun(int y){
		if(y%4==0&&y%100!=0||y%400==0) return true;
		return false;
	}
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区