結果
問題 | No.1464 Number Conversion |
ユーザー |
|
提出日時 | 2021-04-02 22:30:20 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 909 bytes |
コンパイル時間 | 3,458 ms |
コンパイル使用メモリ | 139,580 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-23 20:06:09 |
合計ジャッジ時間 | 4,427 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 |
ソースコード
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { string x; cin >> x; int n = x.length(); int check = -1; ll num1 = 0, num2 = 0; for(int i = 0; i < n; i++) { if(x[i] == '.') { check = i + 1; break; } num1 *= 10; num1 += (ll)(x[i] - '0'); } if(check != -1) { int cnt = 0; for(int i = check; i < n; i++) { num2 *= 10; num2 += (ll)(x[i] - '0'); cnt++; } while(cnt < 8) { num2 *= 10; cnt++; } } ll num3 = 100000000; if(num2 != 0) { ll g = gcd(num2, num3); num2 /= g, num3 /= g; } else { num3 = 1; } num2 += num1 * num3; cout << num2 << "/" << num3 << endl; return 0; }