哈理工院团队赛I题:
Description :
Given N integers, count the number of pairs of integers whose difference is K.
Input Input contains multiple test cases. For each test case , the first line contains N and K. The second line contains N numbers of the set. 2<=N<=10^5 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<iostream>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
long long int a[100001];//为了防止数据超范围全部都开成了long long 。
int main()
{
long long int x,y;
while(scanf("%lld%lld",&x,&y)==2)
{
map<long long int,long long int>m;
for(long long int i=1;i<=x;i++)
{
scanf("%lld",&a[i]);
m[a[i]]++;
}
long long int sum=0;
for(long long int i=1;i<=x;i++)
{
sum+=m[a[i]+y];
}
printf("%lld\n",sum);
}
}