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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值