This is a learning memo.
For example, when the word "Warez" is written in leet, some alphabets are changed to numbers and symbols with similar shapes, such as "W @ rez" and "W4r3z".
This time, convert as follows in Ruby.
Convert characters with Leet for the input character string. After that, the character string is output.
word = gets.chomp.split('') word.each do |w| case w when 'A' print '6' when 'B' print '8' when 'C' print '5' when 'D' print '3' when 'E' print '1' else print w end end
word = gets.chomp.split('')
-In the first line, the input characters are separated one by one into an array and assigned to the word variable. gets method: Receives input as a "character string" line by line. chomp method: Removes line breaks in character strings. split method: Splits a character string into an array.
word.each do |w|
-Assign the element of the word variable to the w variable From the second line onward, match judgment and character replacement are performed character by character depending on the case.