結果
問題 | No.518 ローマ数字の和 |
ユーザー |
![]() |
提出日時 | 2017-05-28 21:27:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,546 bytes |
コンパイル時間 | 1,724 ms |
コンパイル使用メモリ | 177,176 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 15:16:49 |
合計ジャッジ時間 | 2,584 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include "bits/stdc++.h"using namespace std;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }void toRomanNumber1(char i, char v, char x, int n, string &s) {switch (n) {case 0: break;case 1: s += i; break;case 2: s += i, s += i; break;case 3: s += i, s += i, s += i; break;case 4: s += i, s += v; break;case 5: s += v; break;case 6: s += v, s += i; break;case 7: s += v, s += i, s += i; break;case 8: s += v, s += i, s += i, s += i; break;case 9: s += i, s += x; break;default: break;}}string toRomanNumber(int n) {string s(n / 1000, 'M');toRomanNumber1('C', 'D', 'M', n / 100 % 10, s);toRomanNumber1('X', 'L', 'C', n / 10 % 10, s);toRomanNumber1('I', 'V', 'X', n % 10, s);return s;}int main() {map<string, int> a;rer(i, 1, 3999) {a[toRomanNumber(i)]=i;}int N;while (~scanf("%d", &N)) {int sum = 0;rep(i, N) {char buf[101];scanf("%s", buf);sum+=a[buf];}if (sum > 3999) {puts("ERROR");} else {string ans = toRomanNumber(sum);puts(ans.c_str());}}return 0;}