結果

問題 No.2086 A+B問題
ユーザー 👑 chro_96chro_96
提出日時 2022-09-30 21:29:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 29,452 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 14:47:01
合計ジャッジ時間 1,649 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  char a[102] = "";
  char b[102] = "";
  
  int res = 0;
  
  int lena = 0;
  int lenb = 0;
  int lenans = 0;
  char ans[102] = "";
  
  int c = 0;
  
  res = scanf("%s", a);
  res = scanf("%s", b);
  
  while (a[lena] != '\0') {
    lena++;
  }
  while (b[lenb] != '\0') {
    lenb++;
  }
  
  while (lena > 0 || lenb > 0) {
    int tmp = c;
    if (lena > 0) {
      lena--;
      tmp += (int) (a[lena]-'0');
    }
    if (lenb > 0) {
      lenb--;
      tmp += (int) (b[lenb]-'0');
    }
    c = tmp/10;
    ans[lenans] = ((char)(tmp%10))+'0';
    lenans++;
  }
  
  if (c > 0) {
    ans[lenans] = ((char)c)+'0';
    lenans++;
  }
  
  ans[lenans] = '\0';
  for (int i = 0; i < lenans/2; i++) {
    char tmp = ans[i];
    ans[i] = ans[lenans-i-1];
    ans[lenans-i-1] = tmp;
  }
  
  printf("%s\n", ans);
  
  return 0;
}
0