結果
問題 | No.1464 Number Conversion |
ユーザー |
![]() |
提出日時 | 2021-04-04 18:22:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 857 bytes |
コンパイル時間 | 767 ms |
コンパイル使用メモリ | 64,640 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-28 00:59:38 |
合計ジャッジ時間 | 2,131 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 |
ソースコード
#include <iostream> #include <string> using namespace std; using ll = long long int; ll mygcd(ll a, ll b){ while(b != 0){ ll r = a%b; a = b; b = r; } return a; } int main(){ string n0; cin >> n0; ll d = 0; int i; for(i = 0; i < n0.length() && n0[i] != '.'; i++){ d *= 10; d += n0[i]-'0'; } i++; int fketa = 0; ll f = 0; for(; i < n0.length(); i++){ fketa++; f *= 10; f += n0[i]-'0'; } if(fketa == 0) cout << d << "/1" << endl; else{ ll num = d; ll base = 1; for(int i = 0; i < fketa; i++){ num *= 10; base *= 10; } num += f; ll g = mygcd(num, base); num /= g; base /= g; cout << num << "/" << base << endl; } return 0; }