結果
問題 | No.1464 Number Conversion |
ユーザー |
![]() |
提出日時 | 2021-04-02 21:32:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,268 bytes |
コンパイル時間 | 1,214 ms |
コンパイル使用メモリ | 90,184 KB |
最終ジャッジ日時 | 2025-01-20 08:23:23 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template <typename T> T gcd(T a, T b) { if (a < b) swap(a, b); while (b != 0) { T tmp = b; b = a % b; a = tmp; } return a; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; string s; cin >> s; bool f = false; for(char c : s){ if(c == '.') f = true; } if(!f){ cout << s << "/" << 1 << endl; return 0; } ll n = 0; ll d = 1; f = false; for(char c : s){ if(c == '.') { f = true; continue; } if(f){ d *= 10; } n = n*10+(c-'0'); } ll g = gcd(n, d); cout << n/g << '/' << d/g << endl; }