結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2019-10-12 14:54:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,054 bytes |
コンパイル時間 | 598 ms |
コンパイル使用メモリ | 66,176 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 22:58:00 |
合計ジャッジ時間 | 1,446 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 37 | main() | ^~~~
ソースコード
#include<iostream>using namespace std;int f(const string&s){int ret=0;int pre=-114514;for(int i=0;i<s.size();i++){switch(s[i]){case'I':ret+=1;pre=1;break;case'V':ret+=pre==1?3:5;pre=5;break;case'X':ret+=pre==1?8:10;pre=10;break;case'L':ret+=pre==10?30:50;pre=50;break;case'C':ret+=pre==10?80:100;pre=100;break;case'D':ret+=pre==100?300:500;pre=500;break;case'M':ret+=pre==100?800:1000;pre=1000;break;}}return ret;}string g(char a,char b,char c,int t){string ret="";if(t<4){for(int i=0;i<t;i++)ret+=a;}else if(t==4)ret+=a,ret+=b;else if(t<9){ret+=b;for(int i=5;i<t;i++)ret+=a;}else ret+=a,ret+=c;return ret;}main(){int N;cin>>N;int ans=0;for(;N--;){string s;cin>>s;ans+=f(s);}if(ans>=4000){cout<<"ERROR"<<endl;return 0;}string ret="";if(ans/1000)ret+=g('M','0','0',ans/1000);ans%=1000;if(ans/100)ret+=g('C','D','M',ans/100);ans%=100;if(ans/10)ret+=g('X','L','C',ans/10);ans%=10;if(ans)ret+=g('I','V','X',ans);cout<<ret<<endl;}