We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I meant, integer form binary (given as String), sorry. In Ruby (which I'm using for this task) I have two handy methods:
String#to_i which takes base of numeral system as argument and converts String to Integer
Integer#to_s which also takes base of numeral system as argument but converts Integer to String.
And converting on read simply looks like this: students << gets.chomp.to_i(2). It's getting a string from STDIN, removes new line (\n) and to_i(2) converts string to binary (i. e. "101".to_i(2) #=> 5) in the end I'm pushing an integer to students array.
I do converting on read because array of integers is smaller than array of string and I'm doing one convert on read instead two in mergeSkills method.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
ACM ICPC Team
You are viewing a single comment's thread. Return to all comments →
I meant, integer form binary (given as String), sorry. In Ruby (which I'm using for this task) I have two handy methods:
String#to_i which takes base of numeral system as argument and converts String to Integer
Integer#to_s which also takes base of numeral system as argument but converts Integer to String.
And converting on read simply looks like this:
students << gets.chomp.to_i(2)
. It's getting a string from STDIN, removes new line (\n
) andto_i(2)
converts string to binary (i. e."101".to_i(2) #=> 5
) in the end I'm pushing an integer to students array.I do converting on read because array of integers is smaller than array of string and I'm doing one convert on read instead two in
mergeSkills
method.