shouldz

qs 2

May 3rd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. a = File.readlines("teste.txt")
  2. teste = Array.new(a.size)
  3. copia = Array.new(a.size)
  4. valor = 0
  5.  
  6. while valor < teste.size
  7. teste[valor] = a[valor]
  8. copia[valor] = a[valor]
  9. valor +=1
  10. end
  11.  
  12. def converter(str)
  13. begin
  14. Integer(str)
  15. rescue ArgumentError
  16. nil
  17. end
  18. end
  19.  
  20. novo = Array.new(a.size)
  21. contador = 1
  22. start = 1
  23. c = 0
  24. puts teste
  25. until teste.empty?
  26. if teste.size == 1
  27. break
  28. end
  29. if teste[start] == nil
  30. start = 1
  31. end
  32. variavel = teste[start][0]
  33. if converter(variavel) == contador
  34. contador.to_i
  35. novo[c] = teste[start][2]
  36. teste.delete_at(start)
  37. c += 1
  38. contador += 1
  39. end
  40. start += 1
  41. end
  42. puts novo
  43.  
  44.  
  45. =========
  46.  
  47. 7
  48. 4 u
  49. 1 s
  50. 7 z
  51. 3 o
  52. 6 d
  53. 5 l
  54. 2 h
Add Comment
Please, Sign In to add comment