結果
問題 | No.518 ローマ数字の和 |
ユーザー |
![]() |
提出日時 | 2017-07-04 20:24:01 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 1,431 bytes |
コンパイル時間 | 2,348 ms |
コンパイル使用メモリ | 79,668 KB |
実行使用メモリ | 41,336 KB |
最終ジャッジ日時 | 2024-10-05 16:00:01 |
合計ジャッジ時間 | 5,251 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
package yukicoder;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String roma = sc.nextLine();roma = sc.nextLine();int total = 0;String[] spl = roma.split(" ");for(int i = 0 ; i < spl.length ; i++){int subTotal = 0;for(int j = 0 ; j < spl[i].length() ; j++){int num = 0;switch(spl[i].charAt(j)){case 'I' :num = 1;break;case 'V' :num = 5;break;case 'X' :num = 10;break;case 'L' :num = 50;break;case 'C' :num = 100;break;case 'D' :num = 500;break;case 'M' :num = 1000;break;}if(num > subTotal && subTotal !=0){total += num - subTotal;subTotal = 0;}else{total += subTotal;subTotal = num;}}total += subTotal;}int[] numArray = {1000,900,500,400,100,90,50,40,10,9,5,4,1};String[] romaArray = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};int work = total;String disp = "";for(int i = 0 ; i < numArray.length ; i++){int work2 = work/numArray[i];for(int j = 0 ; j < work2 ; j++){disp+=romaArray[i];}work %= numArray[i];}if(total <= 3999){System.out.println(disp);}else{System.out.println("ERROR");}}}