ccf java,CCF节日(Java)

方法一:硬算

import java.util.Scanner;

public class Main {

static int y[] = new int[2051];

static int m1[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

for(int i = 1850; i <= 2050; i++) {

if(i%400==0||(i%4==0&&i%100!=0)) {

y[i] = 1;

}

}

int m = scanner.nextInt();

int n = scanner.nextInt();

int w = scanner.nextInt();

int s = scanner.nextInt();

int e = scanner.nextInt();

for(int i = s;i<=e;i++) {

int day = 0;

for(int j =1850;j

day = day+365+y[j];

}

for(int j = 1; j < m;j++) {

day+=m1[j];

if(j==2) day+=y[i];

}

int ww = day%7+2;

if(ww>7)ww = ww-7;

int cnt = 0,flag = 0;

int mm = (m==2?y[i]:0)+m1[m];

for(int k = 1; k <= mm;k++) {

if(w==ww)cnt++;

if(cnt==n) {

flag =k;

break;

}

ww = ww+1==8?1:ww+1;

}

if(flag == 0) System.out.println("none");

else System.out.println(String.format("%d/%02d/%02d", i,m,flag));

}

}

}

方法二:JavaAPI

import java.time.LocalDate;

import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

import java.util.Scanner;

public class Main {

static int mm[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int m = scanner.nextInt();

int n = scanner.nextInt();

int w = scanner.nextInt();

int s = scanner.nextInt();

int e = scanner.nextInt();

DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy/MM/dd");

for(int i = s; i <= e; i++) {

String q = String.format("%d/%02d/%02d", i,m,1);

LocalDate ldt = LocalDate.parse(q, f);

int ww = ldt.getDayOfWeek().getValue();

mm[2] = ldt.isLeapYear()?29:28;

int cnt = 0;

int k = 1+(w+7-ww);

if(k>7) k-=7;

while(k<=mm[m]) {

cnt++;

if(cnt==n) {

System.out.println(String.format("%d/%02d/%02d", i,m,k));

break;

}

k+=7;

}

if(k>mm[m])System.out.println("none");

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值