View Code of Problem 16

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int i = 0; i < T; i ++) {
			int mode = sc.nextInt();
			String a = sc.nextLine();
			String EL = sc.nextLine();
			String[] split = EL.split("\\+");
			String left = split[0].replace(" ", "");
			split[1] = split[1].replace("=","");
			String right = split[1].replace(" ","");
			left = left.replace("one", "1");
			right = right.replace("one", "1");
			left = left.replace("two", "2");
			right = right.replace("two", "2");
			left = left.replace("three", "3");
			right = right.replace("three", "3");
			left = left.replace("four", "4");
			right = right.replace("four", "4");
			left = left.replace("five", "5");
			right = right.replace("five", "5");
			left = left.replace("six", "6");
			right = right.replace("six", "6");
			left = left.replace("seven", "7");
			right = right.replace("seven", "7");
			left = left.replace("eight", "8");
			right = right.replace("eight", "8");
			left = left.replace("nine", "9");
			right = right.replace("nine", "9");
			left = left.replace("zero", "0");
			right = right.replace("zero", "0");
			int sum = Integer.parseInt(left) + Integer.parseInt(right);
			if(mode == 0) {
				System.out.println(sum);
			} else {
				int len = (sum+"").length();
				String[] num = new String[len];
				int j = len - 1;
				while(j >= 0) {
					num[j--] = sum % 10 + "";
					sum = sum / 10;
				}
				for(j = 0; j < len; j ++) {
					if(num[j].equals("0")) {
						System.out.print("zero");
					}
					if(num[j].equals("1")) {
						System.out.print("one");
					}
					if(num[j].equals("2")) {
						System.out.print("two");
					}
					if(num[j].equals("3")) {
						System.out.print("three");
					}
					if(num[j].equals("4")) {
						System.out.print("four");
					}
					if(num[j].equals("5")) {
						System.out.print("five");
					}
					if(num[j].equals("6")) {
						System.out.print("six");
					}
					if(num[j].equals("7")) {
						System.out.print("seven");
					}
					if(num[j].equals("8")) {
						System.out.print("eight");
					}
					if(num[j].equals("9")) {
						System.out.print("nine");
					}
					if(j == len - 1) {
						System.out.println();
					} else {
						System.out.print(" ");
					}
				}
			}
			
		}
	}

}

/*
Main.c:1:1: error: unknown type name 'import'; did you mean 'short'?
 import java.util.Scanner;
 ^~~~~~
 short
Main.c:1:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
 import java.util.Scanner;
            ^
Main.c:3:1: error: unknown type name 'public'
 public class Main {
 ^~~~~~
Main.c:3:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Main'
 public class Main {
              ^~~~
*/

Double click to view unformatted code.


Back to problem 16