tinycodinglm / misc /misc-0261.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
4.07 kB
opencode trace
System You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code. When solving problems, explain your reasoning step by step before providing...

You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code. When solving problems, explain your reasoning step by step before providing the final solution.

User

"What are your shoe sizes?"

Suddenly, the doctor asked me when I met him for the first time.

"It's 23.5"
"Oh, that's a really nice number. It's 2 to the 4th power plus 2 to the 2nd power, 2 to the 1st power, 2 to the 0th power, and 2 to the 1st power."

Then the doctor asked.

"You, how tall are you?"
"Yes, it's 158.1."

He folded his arms and closed his eyes. After a while of silence, I opened my mouth.

"Nah ~"

After that, during the time I spent together, I gradually became able to understand the behavior of the doctor.

First, I say the real number at the request of the doctor. If the real number is represented by a binary number with no more than 8 digits for the integer part and no more than 4 digits for the decimal part, he is happy to say the result of the conversion to binary. If not, it will sadly yell "Nah ~". This repeats until I say a negative real number.

By the way, as he got older, it became more and more difficult to make long calculations. Therefore, please make a program for you to input real numbers and convert / output them to binary numbers on your behalf. However, if the binary representation does not fit within the limit number of digits (integer part within 8 digits + decimal part within 4 digits), output NA (half-width alphabetic characters). The input real number shall fit within 8 digits of the integer part and within 4 digits of the decimal part, and the binary representation to be output should be output with 8 digits of the integer part and 4 digits of the decimal part.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single negative real line. One real number n is given to one row for each dataset.

The number of datasets does not exceed 1200.

Output

Outputs the conversion result to binary number for each input data set.

Example

Input

23.5
158.1
-1.0

Output

00010111.1000
NA

Assistant

import sys

def process(line):
# Split into integer and fractional parts
parts = line.split('.')
if len(parts) == 1:
integer_str = parts[0]
fractional_str = '0'
else:
integer_str, fractional_str = parts
# Ensure fractional_str is up to 4 digits (though input is guaranteed to be within 4)
fractional_str = fractional_str[:4] # Just in case, though problem says it's within 4

markdown
d = len(fractional_str)
numerator = int(fractional_str)
denominator = 10 ** d

# Process integer part
integer = int(integer_str)
integer_bin = bin(integer)[2:]  # binary without '0b' prefix
if len(integer_bin) > 8:
    return "NA"

# Process fractional part
# Check if (numerator *16) is divisible by denominator
if (numerator * 16) % denominator != 0:
    return "NA"
frac_bin_val = (numerator * 16) // denominator

# Ensure frac_bin_val is within 0-15 (should be already)
if frac_bin_val < 0 or frac_bin_val > 15:
    return "NA"

# Format the integer part to 8 bits with leading zeros
padded_integer = integer_bin.zfill(8)

# Format the fractional part to 4 bits
frac_bin_str = bin(frac_bin_val)[2:].zfill(4)

return f"{padded_integer}.{frac_bin_str}"

def main():
for line in sys.stdin:
line = line.strip()
if not line:
continue
if line[0] == '-':
break
print(process(line))

if name == "main":
main()