A+B=0 | ||||||
| ||||||
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");
}
}