import java.util.Scanner;
class Project{
static int romanNumeralToDecimal(String text){
int[] integerArray=new int[text.length()];
for(byte b=0;b<text.length();b++){
switch(text.charAt(b)){
case 'I':integerArray[b]=1;
break;
case 'V':integerArray[b]=5;
break;
case 'X':integerArray[b]=10;
break;
case 'L':integerArray[b]=50;
break;
case 'C':integerArray[b]=100;
break;
case 'D':integerArray[b]=500;
break;
case 'M':integerArray[b]=1000;
break;
}
}
int sum=integerArray[0];
if(integerArray.length==1){
return(sum);
}
for(byte b=1;b<integerArray.length;b++){
if(integerArray[b]<=integerArray[b-1]){
sum+=integerArray[b];
}
else{
sum+=integerArray[b]-2*integerArray[b-1];
}
}
return(sum);
}
static String decimalToRomanNumeral(int number){
if(number==0){
return("ZERO");
}
byte[] digit=new byte[4];
final char[] romanNumeralCharacters={' ',' ','M','D','C','L','X','V','I'};
String romanNumeralString="";
for(byte i=3;i>=0;i--){
digit[i]=(byte)(number%10);
number/=10;
}
for(byte b=0;b<4;b++){
switch(digit[b]){
case 1: romanNumeralString+=""+romanNumeralCharacters[b*2+2];
break;
case 2: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2];
break;
case 3: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2];
break;
case 4: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+1];
break;
case 5: romanNumeralString+=""+romanNumeralCharacters[b*2+1];
break;
case 6: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2];
break;
case 7: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2];
break;
case 8: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2];
break;
case 9: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2];
break;
default:continue;
}
}
return(romanNumeralString);
}
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
String input=new String();
int[] result=new int[100];
int numberOfInputs=0;
for(int i=0;i<100;i++){
input=scanner.nextLine();
if(input.equals("#")){
numberOfInputs=i;
break;
}
result[i]=Math.abs(romanNumeralToDecimal(input.split(" ")[0])-romanNumeralToDecimal(input.split(" ")[1]));
}
scanner.close();
for(int i=0;i<numberOfInputs;i++){
System.out.println(decimalToRomanNumeral(result[i]));
}
}
}
//zerojudge a013 unsolved
import java.util.Scanner; class Project{ static int romanNumeralToDecimal(String text){ int[] integerArray=new int[text.length()]; for(byte b=0;b=0;i--){ digit[i]=(byte)(number%10); number/=10; } for(byte b=0;b<4;b++){ switch(digit[b]){ case 1: romanNumeralString+=""+romanNumeralCharacters[b*2+2]; break; case 2: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]; break; case 3: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]; break; case 4: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+1]; break; case 5: romanNumeralString+=""+romanNumeralCharacters[b*2+1]; break; case 6: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2]; break; case 7: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]; break; case 8: romanNumeralString+=""+romanNumeralCharacters[b*2+1]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2+2]; break; case 9: romanNumeralString+=""+romanNumeralCharacters[b*2+2]+romanNumeralCharacters[b*2]; break; default:continue; } } return(romanNumeralString); } public static void main(String[] args){ Scanner scanner=new Scanner(System.in); String input=new String(); int[] result=new int[100]; int numberOfInputs=0; for(int i=0;i<100;i++){ input=scanner.nextLine(); if(input.equals("#")){ numberOfInputs=i; break; } result[i]=Math.abs(romanNumeralToDecimal(input.split(" ")[0])-romanNumeralToDecimal(input.split(" ")[1])); } scanner.close(); for(int i=0;i
大概是zerojudge的系統有問題?看解題動態java從2022-12-17 20:29之後每個都是CE