結果
問題 |
No.428 小数から逃げる夢
|
ユーザー |
|
提出日時 | 2021-09-20 14:09:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,586 bytes |
コンパイル時間 | 2,133 ms |
コンパイル使用メモリ | 198,132 KB |
最終ジャッジ日時 | 2025-01-24 16:02:37 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 81 WA * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; string sum(string a,string b) { int carry = 0, n; string t; int aidx, bidx; aidx = a.size() - 1; bidx = b.size() - 1; while (1) { if (aidx < 0 && bidx < 0) { break; } else if (aidx >= 0 && bidx >= 0) { n = (a[aidx] - '0') + (b[bidx] - '0'); n += carry; if (n >= 10) { n -= 10; carry = 1; } else { carry = 0; } t = char(n + '0') + t; aidx--; bidx--; } else if (aidx >= 0 && bidx < 0) { n = a[aidx] - '0'; n += carry; if (n >= 10) { n -= 10; carry = 1; } else { carry = 0; } t = char(n + '0') + t; aidx--; } else if (aidx < 0 && bidx >= 0) { n = b[bidx] - '0'; n += carry; if (n >= 10) { n -= 10; carry = 1; } else { carry = 0; } t = char(n + '0') + t; bidx--; } } if (carry == 1) { t = '1' + t; } return t; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; string A = "0"; string B = "1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991"; cin >> N; for(int i=0;i<N;i++) { A = sum(A,B); } int x = log10(N); if(x==0) { cout << "0." << A << '\n'; } else { for(int i=0;i<A.length();i++) { if(i==x) { cout << "."; } cout << A[i]; } cout << '\n'; } return 0; }