#include #include #include #include #include #include #include #include using namespace std; const long long SCALE = 10000000000LL; class FixedPoint { public: long long sign; long long integer; long long decimal; FixedPoint() : sign(1), integer(0), decimal(0) {} FixedPoint(long long sign, long long integer, long long decimal) : sign(sign), integer(integer), decimal(decimal) {} FixedPoint(const string& s) : sign(1), integer(0), decimal(0) { enum { STATE_SIGN, STATE_INTEGER, STATE_DECIMAL } state = STATE_SIGN; long long digit = SCALE / 10; for (size_t i = 0; i < s.size(); ++i) { char ch = s[i]; switch (state) { case STATE_SIGN: if (ch == '+') { state = STATE_INTEGER; } else if (ch == '-') { sign = -1; state = STATE_INTEGER; } else if (ch == '.') { state = STATE_DECIMAL; } else if (isdigit(ch)) { integer = ch - '0'; state = STATE_INTEGER; } else { throw exception(); } break; case STATE_INTEGER: if (ch == '.') { state = STATE_DECIMAL; } else if (isdigit(ch)) { integer *= 10LL; integer += ch - '0'; } else { throw exception(); } break; case STATE_DECIMAL: if (isdigit(ch)) { decimal += (long long)(ch - '0') * digit; digit /= 10; } else { throw exception(); } break; } } } FixedPoint abs() const { return FixedPoint(1, integer, decimal); } FixedPoint negate() const { if (integer == 0 && decimal == 0) { return *this; } return FixedPoint(sign * -1, integer, decimal); } static FixedPoint add(const FixedPoint& lhs, const FixedPoint& rhs) { assert(lhs.sign > 0 && rhs.sign); long long decimal = lhs.decimal + rhs.decimal; long long integer = lhs.integer + rhs.integer + decimal / SCALE; return FixedPoint(1, integer, decimal % SCALE); } static FixedPoint subtract(const FixedPoint& lhs, const FixedPoint& rhs) { assert(lhs.sign > 0 && rhs.sign); // assert(lhs >= rhs); long long decimal; long long integer; if (lhs.decimal < rhs.decimal) { decimal = SCALE + lhs.decimal - rhs.decimal; integer = lhs.integer - rhs.integer - 1; } else { decimal = lhs.decimal - rhs.decimal; integer = lhs.integer - rhs.integer; } return FixedPoint(1, integer, decimal); } }; bool operator<(const FixedPoint& lhs, const FixedPoint& rhs) { if (lhs.sign != rhs.sign) { return (lhs.sign < rhs.sign); } if (lhs.integer != rhs.integer) { return (lhs.integer * lhs.sign < rhs.integer * rhs.sign); } return (lhs.decimal * lhs.sign < rhs.decimal * rhs.sign); } FixedPoint operator+(const FixedPoint& lhs, const FixedPoint& rhs) { FixedPoint large, small; if (lhs.abs() < rhs.abs()) { small = lhs; large = rhs; } else { small = rhs; large = lhs; } if (large.sign > 0 && small.sign > 0) { return FixedPoint::add(large, small); } else if (large.sign > 0 && small.sign < 0) { return FixedPoint::subtract(large, small.negate()); } else if (large.sign < 0 && small.sign > 0) { return FixedPoint::subtract(large.negate(), small).negate(); } else { return FixedPoint::add(large.negate(), small.negate()).negate(); } } ostream& operator<<(ostream& lhs, const FixedPoint& rhs) { lhs << (rhs.sign < 0 ? "-" : "") << rhs.integer << "." << setfill('0') << setw(10) << rhs.decimal; return lhs; } int main() { int n; cin >> n; vector a; for (int i = 0; i < n; ++i) { string s; cin >> s; a.push_back(FixedPoint(s)); } FixedPoint sum = accumulate(a.begin(), a.end(), FixedPoint()); cout << sum << endl; return 0; }