uva11498 Division of Nlogonia

uva11498

uDebug11498

題意是說,一個被稱爲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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章