পৃষ্ঠাসমূহ

মঙ্গলবার, ১৩ জুন, ২০১৭

12289 - One-Two-Three

import java.util.Scanner;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int cases = scanner.nextInt();
        while (cases-- >= 0) {
            String input = scanner.nextLine();

            switch (input.length()) {
                case 3:
                    int two = 0, one = 0, six = 0, ten = 0;

                    if (input.charAt(0) == 'o') one++;
                    else if (input.charAt(0) == 't') {
                        two++;
                        ten++;
                    } else if (input.charAt(0) == 's') six++;

                    if (input.charAt(1) == 'n') one++;
                    else if (input.charAt(1) == 'w') two++;
                    else if (input.charAt(1) == 'i') six++;
                    else if (input.charAt(1) == 'e') ten++;

                    if (input.charAt(2) == 'e') one++;
                    else if (input.charAt(2) == 'o') two++;
                    else if (input.charAt(2) == 'x') six++;
                    else if (input.charAt(2) == 'n') ten++;

                    if (one == 2 || one == 3) System.out.println(1);
                    else if (two == 2 || two == 3) System.out.println(2);
                    else if (six == 2 || six == 3) System.out.println(6);
                    else if (ten == 2 || ten == 3) System.out.println(8);

                    break;
                case 5:
                    int three = 0, seven = 0, eight = 0;
                    if (input.charAt(0) == 't') three++;
                    else if (input.charAt(0) == 's') seven++;
                    else if (input.charAt(0) == 'e') eight++;

                    if (input.charAt(1) == 'h') three++;
                    else if (input.charAt(1) == 'e') seven++;
                    else if (input.charAt(1) == 'i') eight++;

                    if (input.charAt(2) == 'r') three++;
                    else if (input.charAt(2) == 'v') seven++;
                    else if (input.charAt(2) == 'g') eight++;

                    if (input.charAt(3) == 'e') {
                        three++;
                        seven++;
                    }
                    else if (input.charAt(3) == 'h') eight++;

                    if (input.charAt(4) == 'e') three++;
                    else if (input.charAt(4) == 'n') seven++;
                    else if (input.charAt(4) == 't') eight++;

                    if (three == 4 || three == 5) System.out.println(3);
                    else if (seven == 4 || seven == 5) System.out.println(7);
                    else if (eight == 4 || eight == 5) System.out.println(8);
                    break;
                case 4:
                    int four = 0, five = 0, nine = 0;

                    if (input.charAt(0) == 'f'){
                        four++;
                        five++;
                    }
                    else if (input.charAt(0) == 'n') nine++;

                    if (input.charAt(1) == 'o') four++;
                    else if (input.charAt(1) == 'i') {
                        five++;
                        nine++;
                    }


                    if (input.charAt(2) == 'u') four++;
                    else if (input.charAt(2) == 'v') five++;
                    else if (input.charAt(2) == 'n') nine++;

                    if (input.charAt(3) == 'r') four++;
                    else if (input.charAt(3) == 'e') {
                        five++;
                        nine++;
                    }

                    if (four == 3 || four == 4) System.out.println(4);
                    else if (five == 3 || five == 4) System.out.println(5);
                    else if (nine == 3 || nine == 4) System.out.println(9);


                    break;
            }
        }
    }


}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন