Advertisement
Qpel

ED2.1.Duota simbolių eilutė. Apskaičiuoti kiek joje yra jun

Jan 8th, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. Input.txt   Ir senis, ir vaikas nezinojo, kur eiti jei ir pinigu turetu...
  2.  
  3. counter = 0
  4. data = ''
  5. s = 0
  6. b="ir "
  7. c="Ir "
  8. file = File.new("input.txt", "r")
  9. while (line = file.gets)
  10.     counter = counter + 1
  11.     #puts "#{line}"
  12.     data += line
  13. end
  14. file.close
  15. puts data
  16. for i in 0..data.length-1 do
  17.   if (data[i, b.length] == b) || (data[i, c.length] == c)  
  18.     s = s + 1  
  19.   end
  20. end
  21. puts "Simboliu eiluteje yra #{s} zodziu - #{b}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement