#include #include #include

using namespace std;

int main() { int n, c; cin >> n >> c;

vector<int> nums(n);
for (int i = 0; i < n; i++) {
    cin >> nums[i];
}

int count = 0;
for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
        if (nums[i] - nums[j] == c) {
            count++;
        }
    }
}

cout << count << endl;

return 0;

}

给出一串数以及一个数字 c要求计算出所有 a-b=c 的数对的个数不同位置得到数字一样的数对算不同的数对。输入共两行。第一行两个整数nc 。第二行 a1a2a4 个整数 作为要处理的那串数。输出该数串中包含的满足a-b=c的数对的个数样例输入6 38 4 5 7 7 4样例输出5C++不使用unorderedmap

原文地址: http://www.cveoy.top/t/topic/ja3G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录