名もなき未知

エンジニアリングとか、日常とかそういうのをまとめる場所。アクセス解析のためGAを利用、Googleに情報を送信しています。商品紹介のためAmazonアフィリエイトを利用、Amazonに情報を送信しています。記事に関しては私が書いていない引用文を除いて自由にご利用ください。

Roy and Profile Picture

Roy and Profile Picture** 問題

Roy and Profile Picture | Solve programming problems on HackerEarth

回答

Submission (2166317) for Roy and Profile Picture | HackerEarth

問題文より,

[1] If any of the width or height is less than L, user is prompted to upload another one. Print "UPLOAD ANOTHER" in this case.
[2] If width and height, both are large enough and
(a) if the photo is already square then it is accepted. Print "ACCEPTED" in this case.
(b) else user is prompted to crop it. Print "CROP IT" in this case.

とのことなので,まず指定された長さLよりもW,Hのどちらかが小さければ,"UPLOAD ANOTHER".
次に,図形が正方形ならば,"ACCEPTED",そうでなければ,"CROP IT"です.
確実に問題を読めば解けますね(途中まで勘違いしてた顔)

そうそう,Ruby

5 6

などを読み込む場合は,

w, h = gets.split(" ").map(&:to_i)

とします.知らなかったので覚えておこう(コロンを忘れて混乱してました.)

l = gets.chomp.to_i
n = gets.chomp.to_i
n.times {
	w, h = gets.split(" ").map(&:to_i)
	if w < l or h < l
		puts "UPLOAD ANOTHER"
	elsif w == h
		puts "ACCEPTED"
	else
		puts "CROP IT"
	end
}