結果

問題 No.405 ローマ数字の腕時計
ユーザー sk3388607083sk3388607083
提出日時 2018-06-24 11:09:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 25,868 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-13 13:32:22
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:9: warning: ‘i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   S1[i] = '\0';
   ~~~~~~^~~~~~

ソースコード

diff #

#include<stdio.h>
#include<string.h>

int main(void){
  int i;
  int T;
  char S1[4];
  scanf("%s %d", S1, &T);
  if(strcmp(S1, "IX") == 0) T += 9;
  else{
    for(i = 0; S1[i] != '\0'; i++){
      if(S1[i] == 'I') T += 1;
      else if(S1[i] == 'V') T += 5;
      else if(S1[i] == 'X') T += 10;
    }
  }
  printf("T = %d\n", T);
  if(T >= 0) T = T % 12;
  else T = 12 - (-T % 12);
  if(T == 0) printf("XII\n");
  else if(T == 9) printf("IX\n");
  else{
    i = 0;
    while(1){
      if(T == 0) break;
      else if(T >= 10){
	S1[i] = 'X';
	T = T - 10;
	i++;
      }
      else if(T >= 5){
	S1[i] = 'V';
	T = T - 5;
	i++;
      }
      else if(T >= 1){
	S1[i] = 'I';
	T = T - 1;
	i++;
      }
    }
  }
  S1[i] = '\0';
  printf("%s\n", S1);
  return 0;
}
0