結果
問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
ユーザー |
![]() |
提出日時 | 2016-12-27 00:51:19 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,445 bytes |
コンパイル時間 | 783 ms |
コンパイル使用メモリ | 105,808 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 06:07:49 |
合計ジャッジ時間 | 1,959 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 WA * 4 |
ソースコード
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[24]; foreach(i; 0..n){ string s = readln.chomp; auto ss = s.split('.'); if(s.length == 1){ ss ~= "0"; } int sign = ss[0][0] == '-' ? -1 : +1; ss[0] = ss[0].replace("-", "0"); while(ss[0].length < 12) ss[0] = "0" ~ ss[0]; while(ss[1].length < 12) ss[1] ~= "0"; string x = ss[0] ~ ss[1]; foreach(j; 0..24){ ans[j] += sign * (x[j] - '0'); } } foreach_reverse(i; 1..24){ while(ans[i] >= 10){ ans[i] -= 10; ans[i-1] += 1; } while(ans[i] < 0){ ans[i] += 10; ans[i-1] -= 1; } } int sign = ans[0] < 0 ? -1 : +1; foreach(i; 0..24) ans[i] *= sign; foreach_reverse(i; 1..24){ while(ans[i] >= 10){ ans[i] -= 10; ans[i-1] += 1; } while(ans[i] < 0){ ans[i] += 10; ans[i-1] -= 1; } } // writeln(ans); ans = ans[2..22]; // writeln(ans); auto pos = ans[0..10], neg = ans[10..$]; while(pos.length > 1 && pos[0] == 0){ pos = pos[1..$]; } if(sign < 0) write("-"); write(pos.map!(to!string).join); write("."); writeln(neg.map!(to!string).join); }