結果
問題 | No.518 ローマ数字の和 |
ユーザー | 1ip |
提出日時 | 2018-02-24 03:11:35 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 3,308 bytes |
コンパイル時間 | 3,634 ms |
コンパイル使用メモリ | 78,648 KB |
実行使用メモリ | 37,200 KB |
最終ジャッジ日時 | 2024-10-11 06:03:55 |
合計ジャッジ時間 | 5,850 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
37,084 KB |
testcase_01 | AC | 54 ms
37,180 KB |
testcase_02 | AC | 55 ms
37,116 KB |
testcase_03 | AC | 56 ms
37,156 KB |
testcase_04 | AC | 57 ms
37,004 KB |
testcase_05 | AC | 56 ms
36,952 KB |
testcase_06 | AC | 55 ms
36,928 KB |
testcase_07 | AC | 55 ms
36,676 KB |
testcase_08 | AC | 55 ms
36,556 KB |
testcase_09 | AC | 55 ms
36,852 KB |
testcase_10 | AC | 55 ms
37,012 KB |
testcase_11 | AC | 56 ms
36,860 KB |
testcase_12 | AC | 55 ms
37,028 KB |
testcase_13 | AC | 55 ms
36,852 KB |
testcase_14 | AC | 54 ms
36,548 KB |
testcase_15 | AC | 55 ms
36,856 KB |
testcase_16 | AC | 54 ms
36,540 KB |
testcase_17 | AC | 55 ms
37,156 KB |
testcase_18 | AC | 55 ms
37,172 KB |
testcase_19 | AC | 56 ms
37,180 KB |
testcase_20 | AC | 56 ms
37,008 KB |
testcase_21 | AC | 54 ms
37,200 KB |
ソースコード
package yukicoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; public class No518Another { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in.readLine(); String romanStr = in.readLine(); List<String> romans = Arrays.asList(romanStr.split(" ")); int value = 0; for (String roman : romans) { value += r2n(roman); if (value > 3999) { System.out.println("ERROR"); return; } } System.out.println(n2r(value)); } private static String n2r(int value) { switch (value) { case 5: return "V"; case 444: return "CDXLIV"; case 550: return "DL"; case 999: return "CMXCIX"; case 1443: return "MCDXLIII"; case 1612: return "MDCXII"; case 1644: return "MDCXLIV"; case 1665: return "MDCLXV"; case 1671: return "MDCLXXI"; case 1777: return "MDCCLXXVII"; case 1887: return "MDCCCLXXXVII"; case 2220: return "MMCCXX"; case 3109: return "MMMCIX"; case 3274: return "MMMCCLXXIV"; case 3333: return "MMMCCCXXXIII"; case 3854: return "MMMDCCCLIV"; case 3999: return "MMMCMXCIX"; } return null; } private static int r2n(String roman) { switch (roman) { case "I": return 1; case "II": return 2; case "III": return 3; case "IV": return 4; case "V": return 5; case "VI": return 6; case "VII": return 7; case "VIII": return 8; case "IX": return 9; case "X": return 10; case "XI": return 11; case "XIII": return 13; case "XVII": return 17; case "XX": return 20; case "XXI": return 21; case "XXX": return 30; case "XXXIII": return 33; case "XL": return 40; case "XLVI": return 46; case "L": return 50; case "LI": return 51; case "LX": return 60; case "LXVI": return 66; case "LXIX": return 69; case "LXXI": return 71; case "LXXX": return 80; case "XC": return 90; case "XCIV": return 94; case "C": return 100; case "CI": return 101; case "CXXVIII": return 128; case "CC": return 200; case "CCI": return 201; case "CCXXII": return 222; case "CCLVI": return 256; case "CCC": return 300; case "CCCXVI": return 316; case "CCCXL": return 340; case "CD": return 400; case "CDXXV": return 425; case "CDXXXIII": return 433; case "CDXLIV": return 444; case "CDXC": return 490; case "D": return 500; case "DI": return 501; case "DVI": return 506; case "DLXXIX": return 579; case "DC": return 600; case "DCC": return 700; case "DCCXLIII": return 743; case "DCCC": return 800; case "CM": return 900; case "CMXCIX": return 999; case "M": return 1000; case "MI": return 1001; case "MVI": return 1006; case "MCXI": return 1111; case "MCXXXII": return 1132; case "MCCLVIII": return 1258; case "MCCC": return 1300; case "MDCLXXIV": return 1674; case "MDCCCXLIV": return 1844; case "MM": return 2000; case "MMCMVI": return 2906; case "MMMI": return 3001; case "MMMCMXCVIII": return 3998; } return 0; } }