TOPIC

Wrong Answer 5% help

Marcos Rocha asked 1 year ago

def transhexdec(a):
  somatorio=0
  cont=len(a)-1
  for i in a:
    if(i=='a'):
      i=10
    elif(i=='b'):
      i=11
    elif(i=='c'):
      i=12
    elif(i=='d'):
      i=13
    elif(i=='e'):
      i=14
    elif(i=='f'):
      i=15
    i=int(i)
    somatorio+=(16**cont)*i
    cont-=1
  return somatorio
def transhexbin(a):
  binario=''
  for i in a:
    if(i=='0') and (i!=a[0]):
      binario+='0000'
    elif(i=='1'):
      binario+='0001'
    elif(i=='2'):
      binario+='0010'
    elif(i=='3'):
      binario+='0011'
    elif(i=='4'):
      binario+='0100'
    elif(i=='5'):
      binario+='0101'
    elif(i=='6'):
      binario+='0110'
    elif(i=='7'):
      binario+='0111'
    elif(i=='8'):
      binario+='1000'
    elif(i=='9'):
      binario+='1001'
    elif(i=='a'):
      binario+='1010'
    elif(i=='b'):
      binario+='1011'
    elif(i=='c'):
      binario+='1100'
    elif(i=='d'):
      binario+='1101'
    elif(i=='e'):
      binario+='1110'
    elif(i=='f'):
      binario+='1111'
  return binario
def transbindec(a):
  somatorio=0
  cont=len(a)-1
  for i in a:
    i=int(i)
    somatorio+=(2**cont)*i
    cont-=1
  return somatorio
numero=""
n=int(input())
contador=1
while(n>0):
  numero=''
  case=input()
  tamanho=len(case)
  comando=case[tamanho-3]+case[tamanho-2]+case[tamanho-1]
  for i in case:
    if(i==" "):
      break
    numero+=i
  print("Case %d:" %contador)
  if(comando=='dec'):
    numero1=int(numero)
    print(hex(numero1).split('x')[-1]+" hex")
    print(bin(numero1).split('b')[-1]+" bin\n")

  elif(comando=='hex'):
    res=transhexdec(numero)
    print("%d dec" %res)
    res=transhexbin(numero)
    print("%s bin\n" %res)

  elif(comando=='bin'):
    res=transbindec(numero)
    print("%d dec" %res)
    res=int(res)
    print(hex(res).split('x')[-1]+" hex\n")

  contador+=1
  n-=1

Alguem pode me ajudar a encontrar o erro? Só recebo WA 5%. Could somebody help me find the problem in this code? I'm getting WA 5%.

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.