結果

問題 No.222 引き算と足し算
ユーザー TLwiegehtt
提出日時 2015-07-13 00:13:57
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 668 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 20,736 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-15 21:59:35
合計ジャッジ時間 1,143 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:9:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%s", s);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

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