結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー startcppstartcpp
提出日時 2016-11-08 23:11:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,078 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 59,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 22:34:39
合計ジャッジ時間 1,583 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

signed main() {
	int n;
	cin >> n;
	
	long long ans_i = 0;
	long long ans_f = 0;
	
	while (n--) {
		string s;
		int i;
		long long tmp_i = 0, tmp_f = 0;	//tmp_i + tmp_f * 10^(-10)が与えられた!!
		
		cin >> s;
		for (i = (s[0] == '-'); i < s.length() && s[i] != '.'; i++) { tmp_i *= 10; tmp_i += s[i] - '0'; }
		if (s[i] == '.') { i++; }
		
		int shift = 10 - ((int)s.length() - i);
		for (; i < s.length(); i++) { tmp_f *= 10; tmp_f += s[i] - '0'; }
		for (i = 0; i < shift; i++) { tmp_f *= 10; }
		
		ans_i += (s[0] == '-') ? -tmp_i : tmp_i;
		ans_f += (s[0] == '-') ? -tmp_f : tmp_f;
		
		if (ans_f >= 10000000000) { ans_i++; ans_f -= 10000000000; }	//桁上がり
		if (ans_f < 0) { ans_i--; ans_f += 10000000000; }
		//cout << ans_i << " " << ans_f << endl;
	}
	
	if (ans_i >= 0) printf("%lld.%010lld\n",ans_i, ans_f);
	else {
		if (ans_f <= 0) printf("-%lld.%010lld\n", abs(ans_i), abs(ans_f));
		else printf("-%lld.%010lld\n", abs(ans_i + 1), abs(ans_f - 10000000000));
	}
	return 0;
}
0