Monday, January 23, 2012
My Alphabet Soup Solution
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class C {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int T = in.nextInt();
for (int i = 0; i < T; i++) {
String s = new C().solve(in,i+1);
out.println(s);
System.out.println(s);
}
out.close();
}
private String solve(Scanner in,int caseid) {
// long n = in.nextLong();
// long k = in.nextLong();
int h=0,a=0,c=0,k=0,e=0,r=0,u=0,p=0;
int stats[]={0,0,0,0,0,0,0,0};
String s;
do{
s = in.nextLine();
}while(s.length()<=0);
for(int ii=0;ii<s.length();ii++)
{
char cc=s.charAt(ii);
if(cc=='H'){ h++;stats[0]++;}
if(cc=='A'){ a++;stats[1]++;}
if(cc=='C'){ c++;stats[2]++;}
if(cc=='K'){ k++;stats[3]++;}
if(cc=='E'){ e++;stats[4]++;}
if(cc=='R'){ r++;stats[5]++;}
if(cc=='U'){ u++;stats[6]++;}
if(cc=='P'){ p++;stats[7]++;}
}
stats[2]=(int)(stats[2]/2);
int res=stats[0];
int ri=0;
for(int i=1;i<8;i++)
{
if(stats[i]<res)
{
res=stats[i];
ri=i;
}
}
return "Case #"+(caseid)+": "+res;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment