結果

問題 No.428 小数から逃げる夢
コンテスト
ユーザー kichirb3
提出日時 2018-03-29 14:51:46
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,112 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 793 ms
コンパイル使用メモリ 86,056 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-12 11:21:12
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// No.428 小数から逃げる夢
// https://yukicoder.me/problems/no/428
//
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;
string solve(string digits, int N);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    string D = "0.123456789101112131415161718192021222324252627282930313233343536373839404142";
    D += "4344454647484950515253545556575859606162636465666768697071727374757677787980818283";
    D += "848586878889909192939495969798991";
    int N;
    cin >> N;

    string ans = solve(D, N);
    cout << ans << endl;
}

string solve(string digits, int N) {
    vector<int> res;
    int C = 0;

    for (int i = digits.size()-1; i >= 0; --i) {
        if (digits[i] == '.')
            break;
        int t = (digits[i] - '0') * N + C;
        int cd = t % 10;
        res.push_back(cd);
        C = (t - cd) / 10;
    }

    string ans;
    if (C == 0)
        ans = "0.";
    else
        ans = to_string(C) + ".";
    for (int i = res.size()-1; i >= 0; --i) {
        ans += to_string(res[i]);
    }
    return ans;
}
0