map hrbust 1721

A+B=0
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 696(172 users)Total Accepted: 194(143 users)Rating: Special Judge: No
Description

There is an integer set A. How many couples of a and b, which can make a+b=0(a∈A, b∈A,a<=b).

Input

There are multiple test cases. The first line is an integer T indicating for the number of test cases. The first line of each case is an integer n, standing for the number of integers in set A.

The second line is n integers in set A separated by space.

(1<=n<=100 000,|ai|<=1000 000 000)

Output

For each test case, output all the unique couples of a and b by the order of a from small to large.

If there is no such a situation, output "<empty>".

Output a blank line after each case.


Sample Input

2

6

-1 0 1 4 -1 -4

3

1 1 2

Sample Output

-4 4

-1 1


<empty>

#include<map>
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		map<int,int>ans;
		ans.clear();
		int n;
		scanf("%d",&n);
		int b;
		for(int i = 0 ; i < n; i++)
		{
			scanf("%d",&b);
			ans[b] ++;
		}
		map<int,int>::iterator it;
		int flag = 0;
		for(it = ans.begin(); it->first < 0 && it != ans.end(); it++)
		{
			if(it->second)
			{
				if(ans[-it->first])
				{
					printf("%d %d\n",it->first,-it->first);
					flag = 1;
				} 
			}
		}
		if(ans[0] >= 2)
        {
            printf("0 0\n");
            flag = 1;
        }
        if(flag == 0) printf("<empty>\n");
        printf("\n");
		
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值