
04-22-2004, 05:23 PM
|
 |
Super Moderator
|
|
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
|
|
Yeah... what language?
in java:
Code:
private static String RN(int number){
int[] nums = { 1000, 500, 100, 50, 10, 5, 4, 1};
String[] numerals = { "M", "D", "C", "L", "X", "V", "IV", "I"};
boolean done = false; int x = 0;
while(done == false && x < 8)
{
if(number >= nums[x]){
done = true;
return (numerals[x] + RN(number - nums[x]));
}
x++;
}
return "";
}
private static int number(String RN){
int[] vals = new int[RN.length()];
int total = 0;
for(int x = 0; x < RN.length(); x++)
vals[x] = val(RN.charAt(x));
for(int x = 0; x < RN.length() - 1; x++){
if(vals[x] < vals[x+1])
total -= vals[x];
else
total += vals[x];
}
total += vals[RN.length() - 1];
return total;
}
private static int val(char c){
int[] nums = { 1000, 500, 100, 50, 10, 5, 1};
char[] numerals = { 'M', 'D', 'C', 'L', 'X', 'V', 'I'};
for(int x = 0; x < 7; x++){
if(c == numerals[x])
return nums[x];
}
return 0;
}
__________________
It's not a car, it's an addiction.
The only carb that matters is under the hood.
There's an option for most vehicles that increases brake horsepower, increases mileage, increases driver control, lasts longer than the alternative, and even reduces the price of the vehicle. Despite all this, most people in this country choose the alternative, an automatic transmission.
|