結果
| 問題 |
No.1464 Number Conversion
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:47:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,000 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,768 KB |
| 実行使用メモリ | 54,164 KB |
| 最終ジャッジ日時 | 2025-03-20 20:47:41 |
| 合計ジャッジ時間 | 2,344 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
ソースコード
X = input().strip()
# Split into integer and decimal parts
if '.' in X:
integer_part, decimal_part = X.split('.')
else:
integer_part, decimal_part = X, ''
# Handle cases where integer part is empty (e.g., ".5" becomes "0.5")
if not integer_part:
integer_part = '0'
# Process decimal part by stripping trailing zeros
processed_decimal = decimal_part.rstrip('0')
# Calculate the denominator based on the processed decimal length
n = len(processed_decimal)
denominator = 10 ** n
# Combine the integer and processed decimal parts to get the numerator
combined_str = integer_part + processed_decimal
numerator = int(combined_str) if combined_str else 0
# Handle case where numerator is 0 (output 0/1)
if numerator == 0:
print("0/1")
else:
# Compute GCD and reduce the fraction
import math
gcd_value = math.gcd(numerator, denominator)
simplified_num = numerator // gcd_value
simplified_den = denominator // gcd_value
print(f"{simplified_num}/{simplified_den}")
lam6er