結果

問題 No.1464 Number Conversion
ユーザー ShibuyapShibuyap
提出日時 2021-04-10 15:02:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,419 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 198,820 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:04:33
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// stringを10^keta倍してlongで返す
ll stringToLong(string s, ll keta){
    int n = s.size();
    int dot = -1;
    rep(i,n) if(s[i] == '.') dot = i;
    if(dot == -1){
        s += '.';
        n++;
        dot = n-1;
    }
    while(keta && dot<n-1){
        swap(s[dot],s[dot+1]);
        dot++;
        keta--;
    }
    ll res = 0;
    rep(i,n-1){
        res *= 10;
        res += s[i] - '0';
    }
    rep(i,keta) res *= 10;
    return res;
}

// long version
long long int GCD(long long int x, long long int y){
    if(x == 0 && y == 0) return 0;
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

int main() {
    string sx; cin >> sx;
    ll x = stringToLong(sx, 10);
    ll y = 1;
    rep(i,10) y *= 10;
    ll g = GCD(x,y);
    if(g){
        x /= g;
        y /= g;
    }
        
    cout << x << '/' << y << endl;
    return 0;
}


0