結果

問題 No.222 引き算と足し算
ユーザー くれちーくれちー
提出日時 2016-12-17 21:04:52
言語 C90
(gcc 12.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 502 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 21,376 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-14 04:31:30
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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", str);
      |         ^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define plus 0
#define minus 1

int main() {
	char str[14];
	scanf("%s", str);
	int len = strlen(str);

	int i;
	for (i = 1; str[i] != '+' && str[i] != '-'; i++);
	int op = (str[i] == '+' ? minus : plus);

	char x_[7], y_[7]; 
	strncpy(x_, str, i);
	strncpy(y_, str + i + 1, len - i + 1);
	x_[i] = '\0';
	y_[len - i + 1] = '\0';
	int x = atoi(x_);
	int y = atoi(y_);

	int ans = (op == plus ? x + y : x - y);
	printf("%d\n", ans);
	return 0;
}
0