0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

タイルの敷き詰め

Posted at

H,W = map(int,input().split())
if H > 0 and W > 0:
    if H % 2 == 0 and W % 2 == 0:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

最初は最初のif文なかったんだけど、
テストケースでHやWが0だったときにこれだめなんですよね。
で最初のif文を付け加えたら正解になりました。

ちなみに、上のは入れ子になってますが、最初のif文を逆にしたらelseがいらなくなります。
(ということに今気づいた)
ただし、この場合、andだとだめでorにしないとどちらかが0の場合にNoにならないです。

H,W = map(int,input().split())
if H == 0 or W == 0:
    print('NO')
elif H % 2 == 0 and W % 2 == 0:
    print('YES')
else:
    print('NO')

PHPでも書いておきます。

<?php
   list($H,$W) = explode(" ",fgets(STDIN));
   if ($H == 0 or $W == 0){
       print('NO');
   } elseif ($H % 2 == 0 and $W % 2 == 0){
       print('YES');
   } else {
       print('NO');
   }
?>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?