[Java] Friday the Thirteenth

/* Use the slash-star style comments or the system won't see your
   identification information */
/*
ID: lincans1
LANG: JAVA
TASK: friday
*/
import java.io.*;
import java.util.*;

public class friday {
	private final int WEEK = 7;
	private final int MONTH = 12;
	public static void main (String [] args) throws IOException {
		new friday();
	}
	public friday () throws IOException {
		// Use BufferedReader rather than RandomAccessFile; it's much faster
		BufferedReader f = new BufferedReader(new FileReader("friday.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("friday.out")));
		int N = Integer.parseInt(f.readLine());
		int days = 0, year = 1900;
		// res[0] is Sunday
		int[] res = new int[WEEK];
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= MONTH; j++) {
				res[(days + 13) % WEEK]++;
				switch (j) {
					case 1:
					case 3:
					case 5:
					case 7:
					case 8:
					case 10:
						days += 31;
						break;
					case 4:
					case 6:
					case 9:
					case 11:
						days += 30;
						break;
					case 2:
						if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
							days++;
						days += 28;
						break;
					case 12:
						days += 31;
						year++;
						break;
					}
			}
		}
		for (int i = 0; i < WEEK; i++) {
			out.print(res[(i + 6) % WEEK]);
			if (i != WEEK - 1) {
				out.print(" ");
			}
			else {
				out.println();
			}
		}
		out.close();
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值