結果
| 問題 | 
                            No.518 ローマ数字の和
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-05-28 21:35:14 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,909 bytes | 
| コンパイル時間 | 1,371 ms | 
| コンパイル使用メモリ | 161,404 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-21 15:18:29 | 
| 合計ジャッジ時間 | 2,174 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 3 | 
コンパイルメッセージ
main.cpp: In function ‘int nextInt()’:
main.cpp:11:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   int x; scanf("%d", &x); return x;
      |          ~~~~~^~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chkmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chkmax(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll;
int nextInt() {
  int x; scanf("%d", &x); return x;
}
int f(string s_org) {
  int res = 0;
  for (int i = 0; i < (int)s_org.size(); ) {
    string s = s_org.substr(i, 2);
    if (s == "IV") { res += 4; i += 2; continue; }
    if (s == "IX") { res += 9; i += 2; continue; }
    if (s == "XL") { res += 40; i += 2; continue; }
    if (s == "XC") { res += 90; i += 2; continue; }
    if (s == "CD") { res += 400; i += 2; continue; }
    if (s == "CM") { res += 900; i += 2; continue; }
    s = s_org.substr(i, 1);
    if (s == "I") { res += 1; i += 1; continue; }
    if (s == "V") { res += 5; i += 1; continue; }
    if (s == "X") { res += 10; i += 1; continue; }
    if (s == "L") { res += 50; i += 1; continue; }
    if (s == "C") { res += 100; i += 1; continue; }
    if (s == "D") { res += 500; i += 1; continue; }
    if (s == "M") { res += 1000; i += 1; continue; }
  }
  return res;
}
string g(int n) {
  string s = "";
  while (n >= 1000) { s += "M"; n -= 1000; }
  if (n >= 500) { s += "D"; n -= 500; }
  if (n >= 400) { s += "CD"; n -= 400; }
  while (n >= 100) { s += "C"; n -= 100; }
  if (n >= 50) { s += "L"; n -= 50; }
  if (n >= 40) { s += "XL"; n -= 40; }
  while (n >= 10) { s += "X"; n -= 10; }
  if (n >= 5) { s += "V"; n -= 5; }
  if (n >= 4) { s += "IV"; n -= 4; }
  while (n >= 1) { s += "I"; n -= 1; }
  return s;
}
int main2() {
  int N = nextInt();
  int ans = 0;
  REP(nnn, N) {
    string s; cin >> s;
    ans += f(s);
  }
  if (ans > 3999)
    cout << "ERROR" << endl;
  else
    cout << g(ans) << endl;
  return 0;
}
int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}