結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー Aimee Petrescu
提出日時 2022-11-28 23:55:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 955 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 170,324 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-06 02:34:59
合計ジャッジ時間 3,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 6 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

// unsolved
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  ll ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ll d = 1;
    if (s[0] == '-') d = -1;
    int pos = s.rfind('.');
    if (pos == -1) {
      ans1 += stoi(s);
    } else {
      for (int j = 0; j < pos; j++) {
        if (j == 0 && d == -1) continue;
        ans1 += (s[j] - '0') * pow(10, pos - j - 1) * d;
      }
      for (int j = pos + 1; j < s.size(); j++) {
        ans2 += (s[j] - '0') * pow(10, 9 - (j - pos) + 1) * d;
      }
    }
  }
  ans1 += ll(ans2 / ll(1e10));
  ll ans3 = (abs(ans2) % ll(1e10));
  if (ans1 > 0 && ans2 < 0) {
    ans1 -= 1;
    ans3 = double(ans2 + 1e10);
  } else if (ans1 < 0 && ans2 > 0) {
    ans1 += 1;
    ans3 = double(1e10 - ans2);
  }
  cout << ans1 << ".";
  cout << setfill('0') << left << setw(10) << abs(ans3) % ll(1e10) << endl;
}
0