結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー Aimee PetrescuAimee Petrescu
提出日時 2022-11-28 23:57:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 955 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 165,240 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 21:28:38
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 += stol(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