結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー masamasa
提出日時 2015-02-22 15:12:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 66,004 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-06 02:57:15
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
const long long convert = 1e10;

int main() {
	int n;
	string s;
	long long ans1 = 0; // 整数部
	long long ans2 = 0; // 小数部
	long long tmp;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;

		int pos = s.find('.', 0);
		ans1 += atol(s.substr(0, pos).c_str());

		if (pos != string::npos) {
			tmp = atof(s.substr(pos).c_str()) * convert;
			ans2 += (long long) (s[0] == '-' ? -tmp : tmp);
		}
	}

	// 0 <= ans2 < 1e10 にする
	if (ans2 < 0) {
		ans1 -= abs(ans2) / convert;
		ans2 += abs(ans2) / convert * convert;
	} else {
		ans1 += ans2 / convert;
		ans2 -= ans2 / convert * convert;
	}
	// ans1 ans2の符号を同じにする
	if (ans1 < 0) {
		ans1++;
		ans2 -= convert;
	}

	printf("%lld.%010lld\n", ans1, abs(ans2));
	return 0;
}
0