欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[Java] Friday the Thirteenth

程序员文章站 2022-06-27 23:27:16
/* Use the slash-star style comments or the system won't see your identification information *//*ID: lincans1LANG: JAVATASK: friday*/import java.io.*;import java.util.*;public class friday {private final int WEEK = 7;private final int MONTH...
/* 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();
	}
}

本文地址:https://blog.csdn.net/weixin_41714373/article/details/111844627

相关标签: USACO