結果

問題 No.222 引き算と足し算
コンテスト
ユーザー airuai
提出日時 2016-09-17 20:02:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 446 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 22,528 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 08:18:30
合計ジャッジ時間 1,239 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:4:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |         fgets(str, 100, stdin);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
int main() {
	char* str = new char[100];
	fgets(str, 100, stdin);
	int a1 = 0, a2 = 0, h1 = 1, h2 = 1;
	if (str[0] == '-') {
		h1 = -1;
		++str;
	}
	while(*str >= '0' && *str <= '9'){
		a1 = 10 * a1 + (*str - '0');
		++str;
	}
	if (*str == '+') {
		h2 *= -1;
	}
	++str;
	if (*str == '-') {
		h2 *= -1;
		++str;
	}
	while (*str >= '0' && *str <= '9') {
		a2 = 10 * a2 + (*str - '0');
		++str;
	}
	printf("%d\n", h1*a1 + h2*a2);
}
0