結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー hotpepsi
提出日時 2015-07-30 21:44:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 66,752 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-17 22:40:26
合計ジャッジ時間 1,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	cin >> N;
	long double a = 0, b = 0, d;
	for (int i = 0; i < N; ++i) {
		cin >> d;
		long double n = round(d);

		a += n;
		b += (d - n);
		while (b >= 1) {
			a += 1;
			b -= 1;
		}
		while (b <= -1) {
			a -= 1;
			b += 1;
		}
	}
	if (a < 0) {
		if (b < 0) {
			b = -b;
		} else {
			a += 1;
			b = 1 - b;
		}
	} else {
		if (b < 0) {
			a -= 1;
			b = 1 + b;
		}
	}
	char w[16];
	sprintf(w, "%.10lf", (double)b);
	printf("%lld%s\n", (long long)a, w + 1);
	return 0;
}
0