TOPIC

Wrong answer (100%) Python 3 e Ruby

Wesley Guimarães asked 2 years ago

Eu testei no uDebug e passou os testes, passou até no teste de 99999 inputs

Python 3

lista0 = []
for i in range(0, int(input())):
    s = input()
    lista = [s[2:4], s[5:8], s[-2:]]
    n = 0

    for i in lista:
        if len(i) == 3:
            if not(i[1].isdigit()):
                for a in [n for n in i if n.isdigit()]:
                    n += int(a)
            else:
                n += int("".join([l for l in i if l.isdigit()]))
        else:
            n += int("".join([l for l in i if l.isdigit()]))
    lista0.append(n)

for i in range(0, len(lista0)):
    print(lista0[i])

Ruby

lista0 = []

def numeric(str)
  # https://stackoverflow.com/questions/14551256
  if (str =~ /[0-9]/) == 0
    return true
  else
    return false
  end
end

for i in 0...gets.to_i
  s = gets.to_s.strip
  lista = [s[2, 2], s[5, 3], s[-2, 2]]
  n = 0

  lista.each do |i|
    if i.length == 3
      if not(numeric(i[1]))
        n += (i[0].to_i + i[2].to_i)
      else
        n += i.to_i
      end
    else
      n += i.to_i
    end
  end
  lista0 << n
end

lista0.each do |a|
  puts(a)
end

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