I have exercise below:
The Lavin Interactive Company, which has developed the turn-based
strategy Losers-V, is constantly extending its target market by
localizing the game to as many languages as it can. In particular,
they are interested in creating a version of the game in Anindilyakwa,
which is one of the languages spoken by indigenous Australians.
However, the localization is complicated by the fact that Anindilyakwa
has no numerals. How can a phrase such as “You have seven black
dragons and your enemy has forty black dragons” be translated into
this language? The localizers have decided to translate it as follows:
“You have few black dragons and your enemy has lots of black dragons.”
They have compiled a table showing the rule of replacing numbers of
monsters by Anindilyakwa words.
And my implementation below:
import java.util.Scanner;
public class Localization {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int number;
String designation;
number = s.nextInt();
if (number >= 1 && number <= 4) {
designation = "few";
}else if(number >= 5 && number <= 9){
designation = "several";
}else if(number >= 10 && number <= 19){
designation = "pack";
}else if(number >= 20 && number <= 49) {
designation = "lots";
}else if(number >= 50 && number <= 99){
designation = "horde";
}else if(number >= 100 && number <= 249){
designation = "throng";
}else if(number >= 250 && number <= 499){
designation = "swarm";
}else if(number >= 500 && number <= 999){
designation = "zounds";
}else{
designation = "legion";
}
System.out.println(designation);
}
}
I loaded my code on competition server. And I see next statistics:
Execution time: 0.109
Memory used: 1 434 KB
After this I checked top level results and what I saw:
Rank 1:
Execution time: 0.062
Memory used: 78 KB
Conclusion:
my code two times slower;
my code is used 20 times more memory.
My question: How? How? How is it possible? Why is my code so stupid?
What do I need change to improve my code??
I got it down to 370 KB, 0.78 sec with this code. Kinda bored to get it further…