题意是说,一个被称为Nlogonia的国家,被东西方向和南北方向各一条线划分为东北(NE),西北(NO,葡语,意为NW),西南(SO,葡语,意为SW),东南(SE)四个分区。然后给定分解交叉点,以及居民家的坐标,求该居民家在哪个分区,输出对应字母。如果在分界线上,则输出divisa(葡语,意为边界)。其实就是根据原点和给定点的坐标,判断给定点在哪个象限,或者数轴上。
python版本代码
while True:
testcase = int(input())
if testcase == 0:
break
N,M = input().split()
N = int(N)
M = int(M)
while testcase > 0:
a,b = input().split()
a = int(a)
b = int(b)
dx = a - N
dy = b - M
if dx == 0 or dy == 0:
print("divisa")
elif dx > 0 and dy > 0:
print("NE")
elif dx < 0 and dy > 0:
print("NO")
elif dx < 0 and dy < 0:
print("SO")
elif dx > 0 and dy < 0:
print("SE")
testcase -= 1
C++版本代码
#include <iostream>
#include<cstdio>
using namespace std;
//#define ZANGFONG
int main()
{
#ifdef ZANGFONG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ZANGFONG
int testcase,i,dx,dy,N,M,a,b;
while(scanf("%d\n",&testcase)&& testcase)
{
scanf("%d%d\n",&N,&M);
for(i = 0; i < testcase; i++)
{
scanf("%d%d\n",&a,&b);
dx = a - N;
dy = b - M;
if(dx == 0 || dy == 0) printf("divisa\n");
else if(dx > 0 && dy > 0) printf("NE\n");
else if(dx < 0 && dy > 0) printf("NO\n");
else if(dx < 0 && dy < 0) printf("SO\n");
else if(dx > 0 && dy < 0) printf("SE\n");
}
}
return 0;
}