結果
問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
ユーザー |
![]() |
提出日時 | 2016-12-27 01:05:12 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,167 bytes |
コンパイル時間 | 809 ms |
コンパイル使用メモリ | 106,112 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 06:07:58 |
合計ジャッジ時間 | 1,760 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import std.string, std.stdio, std.algorithm, std.container, std.typecons, std.conv; void main(){ int n; scanf("%d", &n); readln; int[] ans = new int[32]; foreach(i; 0..n){ string s = readln.chomp; int sign = s[0] == '-' ? -1 : +1; if(!s.canFind('.')) s ~= ".0"; auto ss = s.split('.'); ss[0] = ss[0].replace("-", "0"); while(ss[0].length < 16) ss[0] = "0" ~ ss[0]; while(ss[1].length < 16) ss[1] ~= "0"; string x = ss[0] ~ ss[1]; foreach(j; 0..32) ans[j] += sign * (x[j] - '0'); } void carry(){ foreach_reverse(i; 1..32){ while(ans[i] >= 10){ ans[i] -= 10; ans[i-1] += 1; } while(ans[i] < 0){ ans[i] += 10; ans[i-1] -= 1; } } } carry(); int sign = ans[0] < 0 ? -1 : +1; foreach(i; 0..32) ans[i] *= sign; carry(); auto pos = ans[0..16], neg = ans[16..26]; while(pos.length > 1 && pos[0] == 0) pos = pos[1..$]; writeln((sign < 0 ? "-" : "") ~ pos.map!(to!string).join ~ "." ~ neg.map!(to!string).join); }