結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2017-05-28 22:53:43 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,445 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 22,400 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 15:43:47 |
合計ジャッジ時間 | 928 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.c:3:5: warning: conflicting types for built-in function ‘strlen’; expected ‘long unsigned int(const char *)’ [-Wbuiltin-declaration-mismatch] 3 | int strlen(char *s){ | ^~~~~~ main.c:2:1: note: ‘strlen’ is declared in header ‘<string.h>’ 1 | #include<stdio.h> +++ |+#include <string.h> 2 | main.c: In function ‘main’: main.c:69:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 69 | scanf("%d",&n); | ^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>int strlen(char *s){int i=0;while(s[i]!='\0'){i++;}return i;}int convert(char s){switch (s) {case 'I':return 1;case 'V':return 5;case 'X':return 10;case 'L':return 50;case 'C':return 100;case 'D':return 500;case 'M':return 1000;}return 0;}void construct(int a,char m1,char m2,char m3){char s[5];int i=0;switch(a){case 3:s[i]=m1;i++;case 2:s[i]=m1;i++;case 1:s[i]=m1;s[i+1]='\0';printf("%s",s);return;case 4:printf("%c%c",m1,m2);return;case 5:case 6:case 7:case 8:s[0]=m2;for(i=0;i<a-5;i++){s[i+1]=m1;}s[a-4]='\0';printf("%s",s);return;case 9:printf("%c%c",m1,m3);return;case 0:return;}}int main(int argc, char const *argv[]){char r[22];int n,a=0,c,i,p,l,d,b[4];scanf("%d",&n);getchar();while(n>0){i=0;r[0]=getchar();while(r[i]!=' ' && r[i]!='\n'){i++;r[i]=getchar();}l=i;p=0;c=0;for(i=l-1;i>=0;i--){c=convert(r[i]);d=0;while(i-d-1>=0 && r[i]==r[i-d-1]){d++;}if(p!=0 && p>c){a-=c*(d+1);}else{a+=c*(d+1);}p=c;i-=d;}if(a>3999){printf("ERROR\n");return 0;}n--;}for(i=0;i<4;i++){b[i]=a%10;a/=10;}construct(b[3],'M','?','?');construct(b[2],'C','D','M');construct(b[1],'X','L','C');construct(b[0],'I','V','X');printf("\n");return 0;}