結果

問題 No.49 算数の宿題
ユーザー くれちーくれちー
提出日時 2016-11-26 01:34:09
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 24,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:35:21
合計ジャッジ時間 1,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int main() {
	char c;
	char n_[6];
	int n[50];
	char o[50];
	int pn_ = 0, pn = 0, po = 0;

	while ((c = getchar()) != '\n') {
		if (c == '*') {
			o[po++] = c;
			n_[pn_] = '\0';
			n[pn++] = atoi(n_);
			pn_ = 0;
		}
		else if (c == '+') {
			o[po++] = c;
			n_[pn_] = '\0';
			n[pn++] = atoi(n_);
			pn_ = 0;
		}
		else {
			n_[pn_++] = c;
		}
	}
	n_[pn_] = '\0';
	n[pn++] = atoi(n_);
	
	int r = n[0];
	int i;

	for (i = 0; i < pn - 1; i++) {
		if (o[i] == '*') r += n[i + 1];
		else r *= n[i + 1];
	}

	printf("%d\n", r);
	return 0;
}
0