結果

問題 No.4 おもりと天秤
ユーザー ReERishun
提出日時 2020-03-27 04:03:55
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 614 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 26,240 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 07:59:36
合計ジャッジ時間 1,130 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &dataNum);
      |         ^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include <stdlib.h>

int main() {
	int dataNum = 0;
	int data[1000];
	char str;
	int total = 0;
	int harf = 0;

	scanf("%d", &dataNum);

	for (int i = 0; i < dataNum; i++)
		data[i] = 0;

	for (int i = 0; str != '\n'; ) {
		str = getchar();
		if (str == '\0')
			i++;
		else
			data[i] = data[i] * 10 + (int)str - (int)'0';
	}

	// 合計値を求める
	for (int i = 0; i < dataNum; i++)
		total += data[i];

	// 偶数でない場合はimpossible
	if (total % 2 == 0) {
		printf("impossible");
		return 0;
	}

	// 半分の値を求める
	harf = total / 2;

	printf("possible");

	return 0;
}
0