#33273: 我不知道為什麼會compile error(CE)......是JDK版本導致嗎?


a910098@gm.tnfsh.tn.edu.tw (黃亞誠)

學校 : 不指定學校
編號 : 189951
來源 : [36.236.254.107]
最後登入時間 :
2023-01-25 15:35:42
a013. 羅馬數字 -- NPSC 模擬試題 | From: [210.70.138.142] | 發表日期 : 2022-12-19 09:26

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

 
#33275: Re: 我不知道為什麼會compile error(CE)......是JDK版本導致嗎?


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.9.74.255]
最後登入時間 :
2024-10-14 22:20:08
a013. 羅馬數字 -- NPSC 模擬試題 | From: [59.115.1.58] | 發表日期 : 2022-12-19 19:00

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

 
#33277: Re: 我不知道為什麼會compile error(CE)......是JDK版本導致嗎?


Imcyj123 (test.java)

學校 : 朝陽科技大學
編號 : 160420
來源 : [36.232.105.241]
最後登入時間 :
2024-09-30 01:38:28
a013. 羅馬數字 -- NPSC 模擬試題 | From: [114.46.184.210] | 發表日期 : 2022-12-20 21:07

我想說上來玩一下Java 結果一直CE 不給用QQ

 
ZeroJudge Forum