Solve Ruby TGIF

Solve TGIF with ruby

problem

TGIF is an acronym for Thank God It's Friday.

Thank you for welcoming the weekend after a long week of work or school in the Christian culture.

As input, weekday days of the week are given, so ・ For Monday, Tuesday, Wednesday, Thursday, Still (day name) ・ If it is Friday, TGIF Please output.

Value to be entered

The input is given in the following format

s

Expected output

The day of the week given as input is ・ If it is Monday, Tuesday, Wednesday, or Thursday, Still (day name) ・ If it is Friday, TGIF Please output.

Input example 1

Monday

Output example 1

Still Monday

Input example 2

Friday

Output example 2

TGIF

My answer

python


w = gets.to_s
if w == "Monday" || w == "Tuesday" || w == "Wednesday" || w== "Thursday"
    puts "Still" + w.sub("", " ")
elsif w == "Friday"
    puts "TGIF"
end

Commentary

Get the string on the first line.

In the second line, create a code that says if there is an "equal" relationship with the character string obtained using the if statement. "| |"" Is an or sentence, so it means "or".

It is a translation to output with puts on the 3rd line, but this time it is necessary to attach the acquired result to the output result, so concatenate with "+". In addition, if this is left as it is, it will be a bit like "Still Monday" without any space, so if you use the sub method and change "" "" to "" "", space will be available.

In the 4th line, I have to create "If it was Friday" using elsif, so I set it to "Friday" in "Equal".

If "Friday" is equal to puts on the 5th line, "TGIF" will be output.

I think the point this time was probably the sub method </ font>. There is also a method called gsub, and the sub method can be changed pinpointly, but the gsub method can change everything, so it can be used quite as an application!

that's all!

Recommended Posts

Solve Ruby TGIF
Solve Google problems with Ruby
Ruby learning 4
Solve with Ruby AtCoder ABC177 D UnionFind
[Ruby] Array
Ruby basics
Ruby learning 5
Ruby basics
Ruby Review 2
Ruby addition
Refactoring Ruby
Ruby learning 3
Ruby problem ⑦
Ruby learning 2
[Ruby] Block
ruby calculator
Ruby learning 6
Ruby settings 1
Refactoring Ruby
Ruby basics
Ruby memo
Ruby learning 1
Ruby Review 1
[Ruby] Module
[Competition Pro] Solve the knapsack problem with Ruby
AtCoder ABC127 D hash to solve with Ruby 2.7.1