http://oldweb.uwp.edu/academic/mathematics/usaco/2002/spring/problems.htm
Mah solution:
import java.io.*;
class Translate
{
public static void main() throws IOException
{
int sum=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<6;i++)
{
System.out.print("Enter "+(i+1)+"th calf number: ");
sum+=translateIntoNormal(br.readLine());
}
System.out.println("Sum = "+translateIntoCalf(sum));
}
private static int translateIntoNormal(String calfNumber)
{
StringBuffer number = new StringBuffer();
StringBuffer calf = new StringBuffer(calfNumber);
for(int i=0;i
if(calf.charAt(i)==' ')
{
i--;
continue;
}
switch(calf.charAt(i))
{
case 'n': number.append(0); break;
case 'p': number.append(1); break;
case 'r': number.append(2); break;
case 'c': number.append(3); break;
case 'v': number.append(4); break;
case 'm': number.append(5); break;
case 'x': number.append(6); break;
case 'z': number.append(7); break;
case 'b': number.append(8); break;
case 's': number.append(9); break;
}
}
return Integer.parseInt(number.toString());
}
private static StringBuffer translateIntoCalf(int number)
{
StringBuffer calfNumber = new StringBuffer();
while( number>0)
{
calfNumber = calfNumber.insert(0,translate(number%10));
number/=10;
}
return calfNumber;
}
private static String translate(int digit)
{
switch (digit)
{
case 0: return "no";
case 1: return "pa";
case 2: return "re";
case 3: return "ci";
case 4: return "vo";
case 5: return "mu";
case 6: return "xa";
case 7: return "ze";
case 8: return "bi";
case 9: return "so";
default: return "";
}
}
}
n u kno wats scary? i thnk dis is da most efficient solution!!!!
Peace, Yo!
1 comment:
Nice post and this fill someone in on helped me alot in my college assignement. Say thank you you on your information.
Post a Comment