返回题解分享
讨论 / 题解分享/ 帖子详情

日期统计(结果填空) - 题解

最朴实无华的一集,虽然不是很优雅

import java.util.HashSet;

public class Main {
	static int mouths[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	public static void main(String[] args) {

		int[] array = new int[] { 5, 6, 8, 6, 9, 1, 6, 1, 2, 4, 9, 1, 9, 8, 2, 3, 6, 4, 7, 7, 5, 9, 5, 0, 3, 8, 7, 5, 8,
				1, 5, 8, 6, 1, 8, 3, 0, 3, 7, 9, 2, 7, 0, 5, 8, 8, 5, 7, 0, 9, 9, 1, 9, 4, 4, 6, 8, 6, 3, 3, 8, 5, 1, 6,
				3, 4, 6, 7, 0, 7, 8, 2, 7, 6, 8, 9, 5, 6, 5, 6, 1, 4, 0, 1, 0, 0, 9, 4, 8, 0, 9, 1, 2, 8, 5, 0, 2, 5, 3,
				3 };
		HashSet<Integer> hashSet = new HashSet<Integer>();

		for (int a = 0; a < 100; a++) {
			if (array[a] != 2)
				continue;
			for (int b = a + 1; b < 100; b++) {
				if (array[b] != 0)
					continue;
				for (int c = b + 1; c < 100; c++) {
					if (array[c] != 2)
						continue;
					for (int d = c + 1; d < 100; d++) {
						if (array[d] != 3)
							continue;
						for (int e = d + 1; e < 100; e++) {
							for (int f = e + 1; f < 100; f++) {
								for (int g = f + 1; g < 100; g++) {
									for (int h = g + 1; h < 100; h++) {
										int tem = array[e] * 1000 + array[f] * 100 + array[g] * 10 + array[h];
										if (check(array[e] * 10 + array[f],array[g] * 10 + array[h])) {
											hashSet.add(tem);
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(hashSet.size());
	}

	static boolean check(int mouth ,int day) {
		if(mouth<=12&&mouth>0&&day>0&&day<=mouths[mouth]) {
			return true;
		}
		return false;
	}
}
0 回复 0 转发 1 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!