結果

問題 No.405 ローマ数字の腕時計
ユーザー ontama_12ontama_12
提出日時 2016-09-26 16:20:05
言語 JavaScript
(node v21.7.1)
結果
RE  
実行時間 -
コード長 2,792 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 42,616 KB
最終ジャッジ日時 2024-04-21 01:29:36
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 78 ms
40,192 KB
testcase_03 AC 80 ms
42,076 KB
testcase_04 AC 79 ms
41,944 KB
testcase_05 AC 77 ms
39,936 KB
testcase_06 AC 81 ms
40,192 KB
testcase_07 RE -
testcase_08 AC 82 ms
42,332 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 84 ms
42,196 KB
testcase_12 AC 77 ms
39,936 KB
testcase_13 AC 79 ms
41,980 KB
testcase_14 AC 78 ms
41,944 KB
testcase_15 AC 79 ms
39,936 KB
testcase_16 AC 79 ms
39,936 KB
testcase_17 AC 79 ms
42,100 KB
testcase_18 AC 82 ms
42,072 KB
testcase_19 RE -
testcase_20 AC 79 ms
39,936 KB
testcase_21 RE -
testcase_22 AC 79 ms
40,064 KB
testcase_23 RE -
testcase_24 AC 79 ms
42,072 KB
testcase_25 AC 78 ms
42,080 KB
testcase_26 AC 82 ms
42,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    /////////////////////////No.405 ローマ数字の腕時計
    //入力文字読み取り
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on('data', function (chunk) {


        //すべて受け取り改行で区切って格納
        var inputall = chunk.split(" ");

        //何時間進ませるかを数値化
        timelater = Number(inputall[1]);

        //ローマ数字から変換し現代数字をいれる
        var presentnumber = 0;

        //ローマ数字をX,V,Iに分割して解読する
        var romanumber = inputall[0].split("");
        for (var i = 0; i < romanumber.length; i++) {
            if (romanumber[i] == "X") {
                romanumber[i] = 10;
            } else if (romanumber[i] == "V") {
                romanumber[i] = 5;
            } else {
                romanumber[i] = 1;
            }
            presentnumber += romanumber[i];
        }

        // XIだけは上記の方法では変換できないので特別に条件分けする
        if(romanumber[0] ==1 && romanumber[1] ==10){
            presentnumber =9
        }

        //何時間進んだかを計算
        var resultwatch = presentnumber + timelater;

        //答えのローマ数字を入れる際、短針が指し示す数を条件分け
        if (resultwatch <= 12 &&resultwatch >=0) {
        }else if(resultwatch>12){
            resultwatch = Math.floor(reresultwatchsult % 12);
        } else {
            while (true) {
                if (resultwatch >= 0) {
                    break;
                }
                resultwatch += 12
            }
        }

        var resultromawatch =[];
        //ローマ数字に戻して出力
        //X、V、Iをリストに追加していく
        if (resultwatch == 0) {   //0時=12時
            resultromawatch .push("XII")
        } else if (resultwatch == 9) { //9時は変換できないので区別している
            resultromawatch.push("IX")
        }  else {  //その他の時間
            if (resultwatch >= 10) {
                resultromawatch.push("X");
                resultwatch = resultwatch - 10;
            }
            if (resultwatch >= 5) {
                resultromawatch.push("V");
                resultwatch = resultwatch - 5;
            }
            if (resultwatch > 0) {  //4以下は”I”を追加していき0になるまで繰り返し 
                while (true) {
                    if (resultwatch == 0) {
                        break;
                    }
                    resultromawatch.push("I");
                    resultwatch -= 1;
                }
            }
        }
     
        //配列を区切らずに出力
        console.log(resultromawatch.join(""))
    });
0