結果

問題 No.222 引き算と足し算
コンテスト
ユーザー くれちー
提出日時 2016-12-17 21:04:52
言語 C90
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 0 ms / 1,000 ms
+ 784µs
コード長 502 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 75 ms
コンパイル使用メモリ 36,608 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-24 18:35:00
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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