結果
問題 |
No.428 小数から逃げる夢
|
ユーザー |
|
提出日時 | 2021-09-20 14:11:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 1,599 bytes |
コンパイル時間 | 2,193 ms |
コンパイル使用メモリ | 197,156 KB |
最終ジャッジ日時 | 2025-01-24 16:02:48 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#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); } if(N<9) { cout << "0." << A << '\n'; } else { int x = 1; if(N>81) x = 2; for(int i=0;i<A.length();i++) { if(i==x) { cout << "."; } cout << A[i]; } cout << '\n'; } return 0; }