站外题求救!(不知道错在哪爆零了)
查看原帖
站外题求救!(不知道错在哪爆零了)
739307
All_Failed_OI_Cici楼主2024/7/6 11:21

题目如下:

1<=n,x,a[i]<=2000
不知道为什么爆零了(可以帮我看一下吗)

测试数据(样例)

输入

6 3
1 2 5 7 8 11

输出

2
我的代码:

#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,l[N],m,ans;
bool find(int x){
	for(int i=0;i<n;i++){
		if(x==l[i]) return true;
	}
	return false;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	for(int i=0;i<n;i++){
		if(find(l[i]-m)&&find(l[i]+m)) ans++;
	}
	cout<<ans;
	return 0;
}

感觉这是一道语法题很简单,样例也过了,但就是错了 (无语)

2024/7/6 11:21
加载中...