Try   HackMD

Kattis - quadrant

題目連結

題目敘述

A common problem in mathematics is to determine which quadrant a given point lies in. There are four quadrants, numbered from

1 to
4
, as shown in the diagram below:

For example, the point

A, which is at coordinates
(12,5)
lies in quadrant
1
since both its
x
and
y
values are positive, and point
B
lies in quadrant
2
since its
x
value is negative and its
y
value is positive.

Your job is to take a point and determine the quadrant it is in. You can assume that neither of the two coordinates will be

0.

一個數學上常見的問題是給你一個座標點,問你這個點落在第幾象限上。
象限被編號為

1
4
,如圖所示。
(見上圖)

例如座標為

(12,5) 的點
A
因為
x
y
皆為正數,因此落在第一象限;
而點
B
x
為負、
y
為正,因此落在第二象限。
你的任務是對給予的點座標,計算出它落在第幾象限上。
題目保證
x
y
都不會是
0

輸入格式

The first line of input contains the integer

x
(1000x1000;x0)
. The second line of input contains the integer
y
(1000y1000;y0)
.

輸入第一行包含一整數

x 保證
(1000x1000;x0)

第二行包含一整數
y
保證
(1000y1000;y0)

輸出格式

Output the quadrant number

(1,2,3 or
4)
for the point
(x,y)
.

對於點

(x,y) 輸出它所在象限
(1,2,3
或者
4)

Sample Input

10
6

Sample Output

1

Sample Input

9
-13

Sample Output

4
tags: 翻譯, Kattis