結果

問題 No.405 ローマ数字の腕時計
ユーザー ontama_12ontama_12
提出日時 2016-09-26 16:21:05
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,786 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 42,516 KB
最終ジャッジ日時 2023-09-21 00:20:58
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
42,228 KB
testcase_01 AC 84 ms
42,232 KB
testcase_02 AC 82 ms
42,232 KB
testcase_03 AC 80 ms
42,236 KB
testcase_04 AC 83 ms
42,256 KB
testcase_05 AC 82 ms
42,400 KB
testcase_06 AC 84 ms
42,416 KB
testcase_07 AC 83 ms
42,396 KB
testcase_08 AC 82 ms
42,236 KB
testcase_09 AC 81 ms
42,284 KB
testcase_10 AC 82 ms
42,220 KB
testcase_11 AC 82 ms
42,232 KB
testcase_12 AC 81 ms
42,304 KB
testcase_13 AC 81 ms
42,288 KB
testcase_14 AC 81 ms
42,428 KB
testcase_15 AC 81 ms
42,284 KB
testcase_16 AC 83 ms
42,304 KB
testcase_17 AC 83 ms
42,304 KB
testcase_18 AC 83 ms
42,252 KB
testcase_19 AC 82 ms
42,308 KB
testcase_20 AC 84 ms
42,240 KB
testcase_21 AC 85 ms
42,312 KB
testcase_22 AC 82 ms
42,516 KB
testcase_23 AC 81 ms
42,476 KB
testcase_24 AC 82 ms
42,300 KB
testcase_25 AC 82 ms
42,348 KB
testcase_26 AC 82 ms
42,408 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(resultwatch % 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