結果
| 問題 | No.1464 Number Conversion | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-12-10 16:52:18 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,305 bytes | 
| コンパイル時間 | 1,853 ms | 
| コンパイル使用メモリ | 192,180 KB | 
| 最終ジャッジ日時 | 2025-02-09 09:12:46 | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 29 | 
ソースコード
#define PROBLEM "https://yukicoder.me/problems/no/1464"
#include <bits/stdc++.h>
using namespace std;
struct fraction{
    long long p, q; // long long or __int128_t
    fraction(long long P = 0, long long Q = 1): p(P), q(Q){
        normalize();
    }
    void normalize(){
        long long g = __gcd(p, q);
        p /= g, q /= g;
        if(q < 0) p *= -1, q *= -1;
    }
    inline bool operator<(const fraction &other) const {
        return p * other.q < other.p * q;
    }
    inline bool operator<=(const fraction &other) const {
        return p * other.q <= other.p * q;
    }
    inline fraction operator+(const fraction &other) const { return fraction(p * other.q + q * other.p, q * other.q); }
    inline fraction operator-(const fraction &other) const { return fraction(p * other.q - q * other.p, q * other.q); }
    inline fraction operator*(const fraction &other) const { return fraction(p * other.p, q * other.q); }
    inline fraction operator/(const fraction &other) const { return fraction(p * other.q, q * other.p); }
    friend inline ostream& operator<<(ostream& os, const fraction& x) noexcept { return os << x.p << "/" << x.q; }
};
int main(){
    long double x; cin >> x;
    long long n = x * 100000000 + 0.1;
    fraction f = fraction(n, 100000000);
    cout << f << endl;
}
            
            
            
        