(UVA) One-Two-Three - Solution

import java.io.*;
import java.util.*;

class Main {
    public static void process() throws NumberFormatException, IOException {
        Scanner sc = new Scanner(System.in);
       
        String one = "one";
        String two = "two";
        String three = "three";
       
        int numCases = sc.nextInt();
        for (int i = 0; i < numCases; i++) {
            String num = sc.next();
            int value = 0;
            if (num.length() == 3) {
                int count = 0;
                for (int j = 0; j < num.length(); j++) {
                    value = 1;
                    if (num.charAt(j) != one.charAt(j)) {
                        count++;
                    }
                }
               
                if (count > 1) {
                    value = 2;
                }
            }
            else {
                value = 3;
            }
            System.out.println(value);
        }
                               
        return;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main m = new Main();
        m.process();
       
        System.exit(0);
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução