Sunday, June 14, 2015

UVa 10070 - Leap Year or Not Leap Year and ...

// UVa 10070 - Leap Year or Not Leap Year and ...

import java.util.Scanner;

public class Main {

	public static boolean div4(String n) {
		int l = n.length();
		return ((n.charAt(l - 2) - '0') * 10 + (n.charAt(l - 1) - '0')) % 4 == 0;
	}

	public static boolean div100(String n) {
		int l = n.length();
		return ((n.charAt(l - 2) == '0') && (n.charAt(l - 1) == '0'));
	}

	public static boolean div400(String n) {
		int l = n.length();
		return div100(n) && div4(n.substring(0, l - 2));
	}

	public static boolean div55(String n) {
		int l = n.length();
		return (n.charAt(l - 1) == '5' || n.charAt(l - 1) == '0') && div11(n);
	}

	public static boolean div11(String n) {
		int l = n.length();
		int[] sum = new int[2];
		sum[0] = 0;
		sum[1] = 0;
		for (int i = 0; i < l; i++)
			sum[i % 2] += (n.charAt(i) - '0');
		return (sum[0] - sum[1]) % 11 == 0;
	}

	public static boolean div15(String n) {
		int l = n.length();
		return (n.charAt(l - 1) == '5' || n.charAt(l - 1) == '0') && div3(n);
	}

	public static boolean div3(String n) {
		int l = n.length();
		int sum = 0;
		for (int i = 0; i < l; i++)
			sum += (n.charAt(i) - '0');
		return sum % 3 == 0;
	}

	public static void main(String[] args) {
		int t = 0;
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextLine()) {
			String n = scanner.nextLine();
			t++;
			if (t > 1)
				System.out.printf("\n");

			boolean bu = false;
			boolean ordinary = true;
			if (div4(n) && (!div100(n) || div400(n))) {
				System.out.printf("This is leap year.\n");
				ordinary = false;
				if (div55(n))
					bu = true;
			}
			if (div15(n)) {
				System.out.printf("This is huluculu festival year.\n");
				ordinary = false;
			}
			if (bu)
				System.out.printf("This is bulukulu festival year.\n");
			if (ordinary)
				System.out.printf("This is an ordinary year.\n");
		}
	}

}

No comments:

Post a Comment