結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー bal4ubal4u
提出日時 2019-04-12 06:35:31
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-11 14:26:00
合計ジャッジ時間 1,521 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 0 ms
4,356 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 0 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 0 ms
4,372 KB
testcase_14 AC 0 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,356 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 0 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 0 ms
4,356 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.81 すべて足すだけの簡単なお仕事です
// 2019.4.12 bal4u
// 整数部と小数部を分かて足す

#include <stdio.h>
#include <ctype.h>

#define gc() getchar()
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
//	while (isspace(c)) c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (isdigit(c));
	return n;
}

int ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

#define B10  10000000000  // 10^10
char a[50];
long long x[102], y[102]; char minus[102];

char *num(long long *res, char *s)
{
	long long n = 0;
	while (isdigit(*s)) n = 10 * n + (*s++ & 0xf);
	*res = n;
	return s;
}

int main()
{
	int i, w, N;
	char *p;
	long long sx, sy;

	N = in();
	for (i = 0; i < N; i++) {
		// 整数部と小数部に分ける。小数部を正確に10桁に揃う
		ins(p = a);
		if (*p == '-') minus[i] = 1, p++;
		p = num(x + i, p);
		if (*p != '.') y[i] = 0;
		else {
			w = num(y + i, p + 1) - p - 1;
			while (w < 10) w++, y[i] *= 10;  // 桁数を10に揃える
		}
	}

	// 整数部と小数部を別々に加算
	sx = sy = 0;
	for (i = 0; i < N; i++) {
		if (minus[i]) sx -= x[i], sy -= y[i];
		else          sx += x[i], sy += y[i];
	}

	// 桁上げと符号処理
	if (sy >= 0) sx += sy / B10, sy %= B10;
	else         sx -= (-sy) / B10, sy = -((-sy) % B10);

	if (sx == 0) goto frac;
	if (sy != 0) {
		if (sx < 0 && sy > 0) sx++, sy = sy - B10;
		else if (sx >= 0 && sy < 0) sx--, sy = B10 + sy;
	}
	if (sx == 0) {
frac:	if (sy >= 0) printf("0.%010lld\n", sy);
		if (sy < 0) printf("-0.%010lld\n", -sy);
	} else printf("%lld.%010lld\n", sx, sy);
	return 0;
}
0