It will be a memo for learning.
Since the character string s is input, output the nth character and the n + 1st character. n + No output if there is no first character
Input example 1
2
read
Output example 1
e a
n = gets.chomp.to_i
str = gets.chomp
puts "#{str[n - 1]} #{str[n]}" if str[n]
n = gets.chomp.to_i
str = gets.chomp
・ Read what number the character string is in n -Specify a character string with str
puts "#{str[n - 1]} #{str[n]}" if str[n]
-This statement calls the nth character of str and the n + 1 character. -By describing str [n] in the if statement, when the first character or the last character is called, it is not output.
The explanation of the if statement may be difficult to understand. I would appreciate it if you could point out any mistakes.
Recommended Posts