結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-13 18:06:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,462 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 77,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:53:19
合計ジャッジ時間 2,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;
using ll = long long;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int N; cin >> N;

  ll integer = 0, decimal = 0;
  rep(i, N) {
    string s; cin >> s;
    bool negative = s[0] == '-';
    if (negative) s = s.substr(1);
    auto pos = s.find(".");

    if (s == "0") continue;
    if (pos == string::npos)
      integer += (negative ? -1 : 1) * stoll(s);
    else {
      integer += (negative ? -1 : 1) * stoll(s.substr(0, pos));
      int len = s.size() - 1 - pos;
      rep(j, 10-len)
        s += "0";
      s = s.substr(pos+1);
      while (!s.empty() && s[0] == '0') s = s.substr(1);
      if (!s.empty())
        decimal += (negative ? -1 : 1) * stoll(s);
    }
  }

  integer += decimal / 10000000000LL;
  decimal %= 10000000000LL;
  if (integer > 0 && decimal >= 0 || integer < 0 && decimal <= 0) {
    cout << integer << "." << setfill('0') << setw(10) << abs(decimal) << endl;
  } else {
    if (integer == 0) {
      cout << (decimal < 0 ? "-0." : "0.") << setfill('0') << setw(10) << abs(decimal)<<endl;
      return 0;
    }
    if (integer < 0) {
      integer *= -1;
      decimal *= -1;
      cout << "-";
    }
    if (decimal != 0 && integer != 0) --integer;
    cout << integer <<"." << setfill('0') << setw(10) << 10000000000LL-abs(decimal)<<endl;
  }

  return 0;
}
0