NayanaRBhoj
4/22/2019 - 1:23 PM

Google CodeJam 2019 Problem1

Google CodeJam 2019 Problem1

Input is an integer N Output should be two numbers X and Y X+Y=N And X or Y can not contain digit 4

public class CodeJam_Problem1 {
	private static Scanner sc;

	public static void main(String args[]) {
		int Number, NumberOld, Count = 0;
		sc = new Scanner(System.in);

		System.out.println("\n Please Enter any Number: ");
		Number = sc.nextInt();
		NumberOld = Number;
		for (Count = 0; Number > 0; Number = Number / 10) {
			Count = Count + 1;
		}
		System.out.println("Count : " + Count);

		String part1 = Integer.toString(NumberOld);
		String part2 = "";
		for (int k = 0; k < Count; k++) {
			part2 += "0";
		}
		System.out.println("Part1 : " + part1);
		System.out.println("Part2 : " + part2);

		List<String> list1 = new ArrayList();
		List<String> list2 = new ArrayList();
		if (part1.length() == part2.length()) {
			for (int k = 0; k < part2.length(); k++) {
				list1.add(part1.charAt(k) + "");
				list2.add(part2.charAt(k) + "");
			}
		}

		for (int k = 0; k < list1.size(); k++) {
			if (list1.get(k).equalsIgnoreCase("4")) {
				list1.set(k, "3");
				list2.set(k, "1");
			}
		}
		String number1 = "";
		String number2 = "";
		for (int k = 0; k < list1.size(); k++) {
			number1 += list1.get(k);
			number2 += list2.get(k);
		}
		System.out.println("Number 1 is : " + number1 + " Number 2 is : " + number2);
	}
}