結果

問題 No.1464 Number Conversion
ユーザー maru143maru143
提出日時 2021-04-07 16:39:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,992 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 199,672 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 19:53:18
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using pii = pair<i64, i64>;
#define rep(i, n) for (i64 i = 0; i < (i64) n; i++)
#define per(i, n) for (i64 i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (i64 i = a; i < (i64) b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#ifdef LOCAL
#define dbg(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug(__VA_ARGS__)
#else
#define dbg(...)
#endif
template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto& x : vec) { os << x << ' '; } return os;
}
template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& mat) {
    os << endl; for (auto& vec : mat) { os << vec << endl; } return os;
}
template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& pa) {
    os << '(' << pa.first << ',' << pa.second << ')'; return os;
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail> void debug(Head H, Tail... T) {
    cerr << " " << H; debug(T...);
}
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1 << 30) - 1;
const i64 LINF = (1LL << 62) - 1;

void solve() {
    string s;
    cin >> s;
    i64 u = -1, l = -1;
    int n = -1;
    rep(i, s.size()) {
        if (s[i] == '.') {
            n = s.size() - i - 1;
            string upper = s.substr(0, i), lower = s.substr(i + 1, n);
            u = stoll(upper);
            l = stoll(lower);
            break;
        }
    }
    if (u == -1) {
        cout << stoll(s) << "/1" << endl;
        return;
    }
    i64 ten = 1;
    rep(i, n) ten *= 10;
    u = u * ten + l;
    i64 g = gcd(u, ten);
    cout << u / g << "/" << ten / g << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0