結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー mogurockermogurocker
提出日時 2017-10-17 23:59:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,861 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 168,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 07:01:15
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

string f(string s) {
	int pos = -1;
	FOR(i, s.size()) {
		if (s[i] == '.') pos = i;
	}
	string t;
	if (pos == -1) t = string(11-(int)s.size(), '0') + s + string(10, '0');
	else t = string(11-pos, '0') + s.substr(0, pos) + s.substr(pos+1) + string(10-(s.size()-pos-1), '0');
	reverse(ALL(t));
	return t;
}

string calc(string s, string t, int type) {
	string ret = string(21, '0');
	if (type == 0) {
		int c = 0;
		FOR(i, 21) {
			int a = s[i]-'0', b = t[i]-'0', res = a+b+c;
			c = res/10;
			ret[i] = (char)('0'+(res%10));
		}
	}
	else {
		reverse(ALL(s));
		reverse(ALL(t));
		bool minus = false;
		if (s < t) {
			swap(s, t);
			minus = true;
		}
		reverse(ALL(s));
		reverse(ALL(t));
		int c = 0;
		FOR(i, 21) {
			int a = s[i]-'0', b = t[i]-'0', res = a-b-c;
			if (res < 0) {
				c = 1;
				ret[i] = (char)('0'+(res+10));
			}
			else {
				c = 0;
				ret[i] = (char)('0'+res);
			}
		}
		reverse(ALL(ret));
		ret = ret.substr(0, 11) + "." + ret.substr(10);
		int p = 0;
		while (p < 20 && ret[p] == '0') p++;
		ret = ret.substr(min(10, p));
		if (minus) ret = "-" + ret;
	}
	return ret;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	vector<string> plus, minus;
	FOR(i, n) {
		string s;
		cin >> s;
		if (s[0] == '-') minus.push_back(f(s.substr(1)));
		else plus.push_back(f(s));
	}
	string x = string(21, '0');
	FOR(i, plus.size()) {
		string ret = calc(x, plus[i], 0);
		x = ret;
	}
	string y = string(21, '0');
	FOR(i, minus.size()) {
		string ret = calc(y, minus[i], 0);
		y = ret;
	}
	cout << calc(x, y, 1) << endl;
	return 0;
}
0