結果

問題 No.222 引き算と足し算
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-13 00:01:58
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 629 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 20,864 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:44:32
合計ジャッジ時間 978 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 0 ms
6,940 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 0 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 0 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 0 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 0 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 0 ms
6,944 KB
testcase_23 AC 0 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%s", s);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(void){
	
	int pos=0;
	int mul = 0;
	int sum = 0;
	char symbol = '+';
	char s[20];
	scanf("%s", s);
	
	if(s[0] == '-'){
		symbol = '-';
		pos++;
	}else if(s[0] == '+'){
		pos++;
	}
	
	for( ; s[pos] != '\0' ; pos++ ){
		if( '0' <= s[pos] && s[pos] <= '9' ){
			int num = (int)(s[pos] - '0');
			mul = mul * 10 + num;
		}else{
			if(symbol == '+'){
				sum += mul;
				mul = 0;
			}else{
				sum -= mul;
				mul = 0;
			}
			
			if(s[pos] == '+'){
				symbol = '-';
			}else{
				symbol = '+';
			}
		}
	}
	
	if(symbol == '+'){
		sum += mul;
	}else{
		sum -= mul;
	}
	
	printf("%d\n", sum);
	return 0;
}
0