First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Wednesday, July 16, 2014

One-Two-Three.

Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-12289
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3710

Code:

import java.util.*;
public class Uva_12289{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int cases=in.nextInt();
while(cases>0){
String jisan=in.next();
int length=jisan.length();
if(length==3){
int one=0;
int two=0;
if(jisan.charAt(0)=='o'){
one++;
}
if(jisan.charAt(1)=='n'){
one++;
}
if(jisan.charAt(2)=='e'){
one++;
}
if(jisan.charAt(0)=='t'){
two++;
}
if(jisan.charAt(1)=='w'){
two++;
}
if(jisan.charAt(2)=='o'){
two++;
}
if(one>two){
System.out.println(1);
}else{
System.out.println(2);
}
}else{
System.out.println(3);
}
cases--;
}
 }
}

No comments:

Post a Comment