Problem:


金剛の型

以下のように、右から 7 ビット分が小数部、続く24 ビット分が整数部で、一番左の 1 ビット分を符号部とする 32 ビット実数型を考える(b1, ... , b32 は 0 か1 を表す）。

この形式を、人が理解しやすい 10 進数表現に直すときは、以下のように解釈する。

      (-1)符号部 &times; (整数部 + 小数部)

上の表現で、整数部の値は b8 ＋ 21&times;b9 ＋ 22&times;b10＋ ... ＋ 223&times;b31 になる。例えば整数部が

のようになっていた場合、整数部の値は以下のように計算される。

      1 +  21 + 23 = 1 + 2 + 8 =  11

一方、小数部の値は(0.5)1&times;b7＋(0.5)2&times;b6 ＋ ... ＋ (0.5)7 &times; b1 になる。例えば小数部が

のようになっていた場合、小数部は以下のように計算される。

      0.51 + 0.53 = 0.5 + 0.125 = 0.625

さらに、符号部、整数部、小数部を合わせた以下のようなビット列の場合、

ビット列全体が表す10 進数は、以下のようになる(ただし、-1 の0 乗は1)。

(-1)0 &times; (1 + 2 + 8 + 0.5 + 0.125) = 1 &times; (11.625) = 11.625

32 ビットのビット列を Q 個入力すると、それらのビット列が表す実数の10 進表記を一切の誤差無く出
力するプログラムを作成してください。

入力

入力は１つのデータセットからなる。入力データは以下の形式で与えられる。

Q
s1
s2
.
.
.
sQ

1 行目にビット列の数 Q (1 ≤ Q ≤ 10000)が与えられる。続くQ 行に入力ビット列 si が与えられる。 入力ビット列は 16 進数表記で与えられるとする (例: 0111 1111 1000 1000 0000 0000 0000 0000 は 7f880000 と与えられる) 。つまり、Q 行のそれぞれには、2 進数を 4 ビット分ずつまとめた 16 進数が 8 個、空白をはさまずに並んでいる。10 進数、2 進数、16 進数の対応は以下の表のとおりである。

16 進数の英字 a から f までは小文字で与えられる。

出力

各ビット列が表す実数の 10 進表記を 1 行ずつ出力する。ただし、小数部において、ある桁以下がすべて 0 の場合、その桁以下は省略するものとするが、例外として小数部が 0 の場合は小数部には 0 ひとつを出力する。

入力例

8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70

出力例

0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875



Sample input:
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70


Sample output:
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875

Submission status: Wrong Answer

Solution code:
for _ in range(input()):
    k = raw_input()
    s = ""
    for i in k:
        s += format(int(i,16),'b').zfill(4)
    ans = 0.0
    for i in range(1,32):
        if int(s[i]): ans += 2 ** (24-i)
    print ans*(-1) if int(s[0]) else ans

Submission status: Wrong Answer

Solution code:
def to_binary(s_16):
    s_2 = []
    for tmp in s_16:
        tmp_10 = int(tmp, 16)
        if tmp_10 >= 8:
            s_2.append("1")
            tmp_10 -= 8
        else:
            s_2.append("0")
        if tmp_10 >= 4:
            s_2.append("1")
            tmp_10 -= 4
        else:
            s_2.append("0")
        if tmp_10 >= 2:
            s_2.append("1")
            tmp_10 -= 2
        else:
            s_2.append("0")
        if tmp_10 >= 1:
            s_2.append("1")
            tmp_10 -= 1
        else:
            s_2.append("0")
    return s_2

def is_int(s_2):
    b = True
    for i in s_2[25:]:
        if i == '1':
            b = False
            break
    return b

Q = input()
for i in range(Q):
    s_16 = raw_input()
    s_2 = to_binary(s_16)
    num_10 = 0.0
    for i in range(1, 32):
        if i <= 24:
            if s_2[i] == "1":
                num_10 += 2 ** (24-i)
        else:
            if s_2[i] == "1":
                num_10 += 0.5 ** (i-24)
    if s_2[0] == "1":
        if is_int(s_2):
            print "-%.1f" % num_10
        else:
            print "-%s" % str(num_10)

    else:
        if is_int(s_2):
            print "%.1f" % num_10
        else:
            print "%s" % str(num_10)

Submission status: Wrong Answer

Solution code:
def to_binary(s_16):
    s_2 = []
    for tmp in s_16:
        tmp_10 = int(tmp, 16)
        if tmp_10 >= 8:
            s_2.append("1")
            tmp_10 -= 8
        else:
            s_2.append("0")
        if tmp_10 >= 4:
            s_2.append("1")
            tmp_10 -= 4
        else:
            s_2.append("0")
        if tmp_10 >= 2:
            s_2.append("1")
            tmp_10 -= 2
        else:
            s_2.append("0")
        if tmp_10 >= 1:
            s_2.append("1")
            tmp_10 -= 1
        else:
            s_2.append("0")
    return s_2

def is_int(s_2):
    b = True
    for i in s_2[25:]:
        if i == '1':
            b = False
            break
    return b

Q = input()
for i in range(Q):
    s_16 = raw_input()
    s_2 = to_binary(s_16)
    num_10 = 0
    for i in range(1, 32):
        if s_2[i] == "1":
            num_10 += 2 ** (31-i)
    """
        if i <= 24:
            if s_2[i] == "1":
                num_10 += 2 ** (31-i)
        else:
            if s_2[i] == "1":
                num_10 += 0.5 ** (i-24)
        """
    print num_10
    num_10 /= 128.0
    if s_2[0] == "1":
        if is_int(s_2):
            print "-%.1f" % num_10
        else:
            print "-%s" % str(num_10)

    else:
        if is_int(s_2):
            print "%.1f" % num_10
        else:
            print "%s" % str(num_10)

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s=""
    for c in raw_input():
        t=format(int(c,16),"b")
        s+="0"*(4-len(t))+t
    s=s[::-1]
    print pow(-1,int(s[31]))*sum(pow(2,i-7)*int(s[i]) for i in range(0,31))

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s=""
    for c in raw_input():
        t=format(int(c,16),"b")
        s+="0"*(4-len(t))+t
    print pow(-1,int(s[0]))*sum(pow(2,i)*int(s[24-i]) for i in range(-7,24))

Submission status: Wrong Answer

Solution code:
for i in range(input()):
    s=""
    for c in raw_input():
        t=format(int(c,16),"b")
        s+="0"*(4-len(t))+t
    p=int(s[1:25],2)
    f=sum(pow(2,-(i+1))*int(s[25+i]) for i in range(7))
    print pow(-1,int(s[0]))*(p+f)

Submission status: Wrong Answer

Solution code:
D={'a': '1010', 'c': '1100', 'b': '1011', 'e': '1110', 'd': '1101', 'f': '1111'\
, '1': '0001', '0': '0000', '3': '0011', '2': '0010', '5': '0101', '4': '0100',\
 '7': '0111', '6': '0110', '9': '1001', '8': '1000'}
for i in range(input()):
    s="".join(D[c] for c in raw_input())
    p=int(s[1:25],2)
    f=sum(pow(2,-(i+1))*int(s[25+i]) for i in range(7))
    print pow(-1,int(s[0]))*(p+f)

Submission status: Wrong Answer

Solution code:
D={'a': '1010', 'c': '1100', 'b': '1011', 'e': '1110', 'd': '1101', 'f': '1111'\
, '1': '0001', '0': '0000', '3': '0011', '2': '0010', '5': '0101', '4': '0100',\
 '7': '0111', '6': '0110', '9': '1001', '8': '1000'}
for i in range(input()):
    s="".join(D[c] for c in raw_input())
    p=int(s[1:25],2)
    f=sum(pow(0.5,i+1)*int(s[25+i]) for i in range(7))
    print "%s%s"%("-" if s[0]=="1" else "",str(p+f))

Submission status: Wrong Answer

Solution code:
hexToBi={"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101","6":"0110",
         "7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100","d":"1101",
         "e":"1110","f":"1111"}
convDec=[5000000,2500000,1250000,625000,312500,156250,78125]
Q=input()
for i in range(Q):
    s="".join(hexToBi[ch] for ch in raw_input())
    sign=s[0]
    integer=s[1:-7]
    dec=map(int,s[-7:])
    large=int(integer,2)
    small=sum(i*j for i,j in zip(dec,convDec))
    small=str(small).rstrip("0")
    small=0 if small=="" else int(small)
    print "%d.%d"%(large,small) if sign=="0" else "-%d.%d"%(large,small)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for j in range(n):
    b = bin(eval('0x' + raw_input().strip()))
    b = '0' * (32 - len(b[2:])) + b[2:]
    s = b[0]
    i = b[1:-7]
    d = b[-7:]

    s = '' if s == '0' else '-'
    i = eval('0b' + i)
    d = sum([int(d[x]) * (1.0 / 2 ** (x + 1)) for x in range(len(d))])

    print s + str(i + d)

Submission status: Wrong Answer

Solution code:
for j in range(int(raw_input())):
    b = bin(eval('0x' + raw_input()))
    b = '0' * (32 - len(b[2:])) + b[2:]
    s = b[0]
    i = b[1:-7]
    d = b[-7:]

    s = '' if s == '0' else '-'
    i = eval('0b' + i)
    d = sum([1.0 / 2 ** (x + 1) for x in range(len(d)) if d[x] == '1'])

    print s + str(float(i + d))

Submission status: Wrong Answer

Solution code:
import sys

while True:
    try:
        for j in range(int(raw_input())):
            b = bin(eval('0x' + raw_input()))
            b = '0' * (32 - len(b[2:])) + b[2:]
            s = b[0]
            i = b[1:-7]
            d = b[-7:]

            s = '' if s == '0' else '-'
            i = eval('0b' + i)
            d = sum([1.0 / 2 ** (x + 1) for x in range(len(d)) if d[x] == '1'])

            print s + str(float(i + d))
    except EOFError:
        sys.exit()

Submission status: Wrong Answer

Solution code:
try:
	for i in range(input()):
		hex=raw_input()
		bit=""
		for j in b:
			bit+=format(int(j,16),"b").zfill(4)
		ans=0.0
		for i in range(1,32):
			ans+=int(bit[i])*2.0**(24-i)
		print (-1)**int(bit[0])*ans
except:
	pass

Submission status: Wrong Answer

Solution code:
for i in range(input()):
	try:
		hex=raw_input()
		bit=""
		for j in b:
			bit+=format(int(j,16),"b").zfill(4)
		ans=0.0
		for i in range(1,32):
			ans+=int(bit[i])*2.0**(24-i)
		print (-1)**int(bit[0])*ans
	except:
		pass

Submission status: Wrong Answer

Solution code:
for i in range(input()):	
	hex=raw_input()
	bit=""
	for j in hex:
		bit+=format(int(j,16),"b").zfill(4)
	ans=0.0
	for i in range(1,32):
		ans+=int(bit[i])*2.0**(24-i)
	print (-1)**int(bit[0])*ans

Submission status: Wrong Answer

Solution code:
for i in range(input()):	
	bit=format(int(raw_input(),16),"b").zfill(32)
	ans=0.0
	for i in range(1,32):
		ans+=int(bit[i])*2.0**(24-i)
	print (-1)**int(bit[0])*ans

Submission status: Wrong Answer

Solution code:
for i in range(input()):	
	bit=format(int(raw_input(),16),"b").zfill(32)
	ans=0.0
	for i in range(1,32):
		ans+=int(bit[i])*2**(24-i)
	print (-1)**int(bit[0])*ans

Submission status: Wrong Answer

Solution code:
for i in range(input()):	
	b=format(int(raw_input(),16),"b").zfill(32)
	a1=0
	a2=0.0
	for i in range(1,25):
		a1+=int(b[i])*2**(24-i)
	for i in range(25,32):
		a2+=int(b[i])*2**(24-i)
	print "-1"*int(b[i])+str(a1)+str(a2)[1:]

Submission status: Wrong Answer

Solution code:
for i in range(input()):	
	b=format(int(raw_input(),16),"b").zfill(32)
	a1=0
	a2=0.0
	for i in range(1,25):
		a1+=int(b[i])*2**(24-i)
	for i in range(25,32):
		a2+=int(b[i])*2**(24-i)
	print "-1"*int(b[0])+str(a1)+str(a2)[1:]

Submission status: Wrong Answer

Solution code:
for i in range(input()):    
	b=int(raw_input(),16)
	s=1<<31
	if b&s!=0:
		b^=s
		b*=-1
	print b*1.0/(1<<7)

Submission status: Wrong Answer

Solution code:
for i in range(input()):    
	b=int(raw_input(),16)
	s=1<<31
	if b&s!=0:
		b^=s
		b*=-1
	a=int(b*1.0/(1<<7))
	print str(a)+str(abs(b*1.0/(1<<7)-a))[1:]

Submission status: Accepted

Solution code:
BIN = [0] * 32

v = 1
for i in range(24, 0, -1):
    BIN[i] = v
    v *= 2
v = float(1) / 2
for i in range(25, 32):
    BIN[i] = v
    v /= 2

Q = int(input())

for i in range(Q):
    inp = format(int(input(),16),'b').zfill(32)
    res = float(0)
    for j, v in enumerate(list(inp)[1:]):
        #print(str(BIN[j]) + ' ' + v + ' '  + str(float(v) * BIN[j]))
        res += BIN[j+1] * int(v)

    print(('-' if inp[0] == '1' else '') + str(res))

Submission status: Accepted

Solution code:
for _ in range(input()):
    k = int(raw_input(),16)
    a= ""
    if k&(1<<31):
        a = "-"
        k ^= 1<<31
    b = int(k*1.0/(1<<7))
    print a + str(b) + str(k*1.0/(1<<7)-b)[1:]

Submission status: Accepted

Solution code:
from decimal import Decimal

def to_binary(s_16):
    s_2 = []
    for tmp in s_16:
        tmp_10 = int(tmp, 16)
        if tmp_10 >= 8:
            s_2.append("1")
            tmp_10 -= 8
        else:
            s_2.append("0")
        if tmp_10 >= 4:
            s_2.append("1")
            tmp_10 -= 4
        else:
            s_2.append("0")
        if tmp_10 >= 2:
            s_2.append("1")
            tmp_10 -= 2
        else:
            s_2.append("0")
        if tmp_10 >= 1:
            s_2.append("1")
            tmp_10 -= 1
        else:
            s_2.append("0")
    return s_2

def is_int(s_2):
    b = True
    for i in s_2[25:]:
        if i == '1':
            b = False
            break
    return b

Q = input()
for i in range(Q):
    s_16 = raw_input()
    s_2 = to_binary(s_16)
    num_10 =  Decimal("0.0")
    for i in range(1, 32):
        if i <= 24:
            if s_2[i] == "1":
                tmp = 2 ** (24-i)
                num_10 += Decimal(str(tmp))
        else:
            if s_2[i] == "1":
                tmp = 0.5 ** (i-24)
                num_10 += Decimal(str(tmp))
    if s_2[0] == "1":
        if is_int(s_2):
            print "-%.1f" % num_10
        else:
            print "-%s" % str(num_10)

    else:
        if is_int(s_2):
            print "%.1f" % num_10
        else:
            print "%s" % str(num_10)

Submission status: Accepted

Solution code:
# Aizu Problem 0268: Konto Type

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
for _ in range(n):
    k = int(input(), 16)
    s = 1 << 31
    p = ""
    if k & s != 0:
        k ^= s
        p = "-"
    a = int(k * 1.0 / (1 << 7))
    print(p + str(a) + str(abs(k * 1.0 / (1 << 7) - a))[1:])

Submission status: Accepted

Solution code:
hex_to_dig = {"0":"0000", "1":"0001", "2":"0010", "3":"0011",
              "4":"0100", "5":"0101", "6":"0110", "7":"0111",
              "8":"1000", "9":"1001", "a":"1010", "b":"1011",
              "c":"1100", "d":"1101", "e":"1110", "f":"1111"}
def dig_to_dec(digit):
  tf = digit[0]
  x = digit[1:25][::-1]
  y = digit[25:32]
  
  sumx = 0
  acc = 1
  for i, c in enumerate(x):
    if c == "1":
      sumx += acc
    acc *= 2
  
  sumy = 0
  acc = 0.5
  for i, c in enumerate(y):
    if c == "1":
      sumy += acc
    acc /= 2
  
  tf = "-" if int(tf) == 1 else ""
  if sumy == 0:
    print(tf + str(sumx) + "." + "0")
  else:
    print(tf + str(sumx + sumy))

n = int(input())
for _ in range(n):
  h = input()
  d = ""
  for c in h:
    d += hex_to_dig[c]
  dig_to_dec(d)

Submission status: Accepted

Solution code:
hexToBi={"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101","6":"0110",
         "7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100","d":"1101",
         "e":"1110","f":"1111"}
convDec=[5000000,2500000,1250000,625000,312500,156250,78125]
Q=input()
for i in range(Q):
    s="".join(hexToBi[ch] for ch in raw_input())
    sign=s[0]
    integer=s[1:-7]
    dec=map(int,s[-7:])
    large=int(integer,2)
    small=sum(i*j for i,j in zip(dec,convDec))
    small=str(small).zfill(7).rstrip("0")
    small="0" if small=="" else small
    print "%d.%s"%(large,small) if sign=="0" else "-%d.%s"%(large,small)

Submission status: Accepted

Solution code:
for i in range(input()):	
	b=format(int(raw_input(),16),"b").zfill(32)
	a1=0
	a2=0.0
	for i in range(1,25):
		a1+=int(b[i])*2**(24-i)
	for i in range(25,32):
		a2+=int(b[i])*2**(24-i)
	print "-"*int(b[0])+str(a1)+str(a2)[1:]

Submission status: Accepted

Solution code:
for i in range(input()):    
	b=int(raw_input(),16)
	s=1<<31
	p=""
	if b&s!=0:
		b^=s
		p="-"
	a=int(b*1.0/(1<<7))
	print p+str(a)+str(abs(b*1.0/(1<<7)-a))[1:]

Submission status: Accepted

Solution code:
q = int(input())
for _ in range (q):
    bits = F'{int(input(), 16):32b}'
    sign = '-' if bits[0] == '1' else ''
    integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1'])
    fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1'])
    print(sign + str(float(integer + fraction)))

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    s = int(input(), 16)
    ans = (s & ~(1 << 31)) >> 7
    v = 0.5
    for i in range(6, -1, -1):
        if (s >> i) & 1:
            ans += v
        v /= 2
    if s & (1 << 31):
        t = "-%.10f" % ans
    else:
        t = "%.10f" % ans
    i = len(t)
    while t[i-1] == '0':
        i -= 1
    if t[i-1] == '.':
        i += 1
    print(t[:i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Kongo Type
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0268

"""
import sys


def solve():
    bits = f'{int(input(), 16):032b}'
    sign = '-' if bits[0] == '1' else ''
    integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1'])
    fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1'])
    return sign + str(float(integer + fraction))


def main(args):
    Q = int(input())
    for _ in range(Q):
        ans = solve()
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:

N = int(input())
for i in range(N):
    S = str(input())
    bit = bin(int(S, 16))[2:].zfill(32)

    bit = bit[::-1]
    # print(bit)
    pos = (-1)**int(bit[31])
    up = int(bit[7:31][::-1], 2)
# print(bit[7:31],len(bit[7:31]), int(bit[7:31], 2))
    # print(bit[:7],len(bit[:7]))

    # print(up)
    low = 0
    pow = 0.5
    for b in bit[:7][::-1]:
        # print(pow*int(b))
        low = low + pow*int(b)
        # print(int(b))
        pow *= 0.5
    # print(low)

    print(pos*(up+low))

Submission status: Runtime Error

Solution code:
BIN = [0] * 32

v = 1
for i in range(24, 0, -1):
    BIN[i] = v
    v *= 2
v = float(1) / 2
for i in range(25, 32):
    BIN[i] = v
    v /= 2

while 1:
    Q = int(input())
    if not Q:break

    for i in range(Q):
        inp = format(int(input(),16),'b').zfill(32)
        res = float(0)
        for j, v in enumerate(list(inp)[1:]):
            #print(str(BIN[j]) + ' ' + v + ' '  + str(float(v) * BIN[j]))
            res += BIN[j+1] * int(v)

        print(('-' if inp[0] == '1' else '') + str(res))

Submission status: Runtime Error

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    for j in range(n):
        b = bin(eval('0x' + raw_input()))
        b = '0' * (32 - len(b[2:])) + b[2:]
        s = b[0]
        i = b[1:-7]
        d = b[-7:]

        s = '' if s == '0' else '-'
        i = eval('0b' + i)
        d = sum([1.0 / 2 ** (x + 1) for x in range(len(d)) if d[x] == '1'])

        print s + str(float(i + d))

Submission status: Runtime Error

Solution code:
for i in range(input()):
	hex=raw_input()
	bit=""
	for j in b:
		bit+=format(int(j,16),"b").zfill(4)
	ans=0.0
	for i in range(1,32):
		ans+=int(bit[i])*2.0**(24-i)
	print (-1)**int(bit[0])*ans

Submission status: Runtime Error

Solution code:
gets
$<.map{|l|n=0.0;b=l.hex;31.times{|i|n+=(2**(24-i))*b[i]};p n*(-1)**b[31]}