/*
今天头条2018春招笔试题在n个元素的数组中,找到差值为k的数字对去重后的个数输入描述:第一行,n和k,n表示数字个数,k表示差值第二行,n个正整数。示例1:输入:5 21 5 3 4 2输出:3示例2:输入:6 21 5 3 3 4 2输出:3示例3:输入:4 01 1 1 1输出:1*///author:sandy#include <bits/stdc++.h>using namespace std;int main(){ vector<int>vec; int n, k; cin >> n >> k; int i = 0, m; while (i<n&&cin>>m) vec.push_back(m),++i; sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end());//去重,并删除后面的元素 int num = 0; for (auto j = vec.begin(); j != vec.end(); ++j) for (auto r = j; r != vec.end();++r) if (abs(*j - *r) == k) ++num; cout << num << endl; return 0;}