結果
| 問題 | No.405 ローマ数字の腕時計 |
| コンテスト | |
| ユーザー |
ontama_12
|
| 提出日時 | 2016-09-26 16:21:05 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 2,786 bytes |
| 記録 | |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 7,072 KB |
| 実行使用メモリ | 42,076 KB |
| 最終ジャッジ日時 | 2024-07-06 19:06:17 |
| 合計ジャッジ時間 | 3,078 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
/////////////////////////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(""))
});
ontama_12