Pages

Friday 7 December 2012

UVA - 12289 - One-Two-Three (Java solution)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
   
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer("");
        int n=Integer.parseInt(br.readLine());
        for(int i=0;i<n;i++){
            sb.append(strMatch(br.readLine())).append("\n");
        }
        System.out.print(sb);
    }
   
    static int strMatch(String x){
        if(x.length()==3){
           int two=0,one=0;
           if(x.charAt(0)=='o'){
               one++;
           }
           if(x.charAt(1)=='n'){
               one++;
           }
           if(x.charAt(2)=='e'){
               one++;
           }
           if(x.charAt(0)=='t'){
               two++;
           }
           if(x.charAt(1)=='w'){
               two++;
           }
           if(x.charAt(2)=='o'){
               two++;
           }
           if(one>two){
               return 1;
           }
           return 2;
        }else{
            return 3;
        }
    }
}

No comments:

Post a Comment