数据过水
查看原帖
数据过水
1287433
__ycy1124__楼主2024/10/12 08:18

在这道题中,答案还要取排序后相邻两数的大的 mod 小的的结果的 max,但是我一开始想错了,取得是差,但是通过了此题。

错误代码:

#include<bits/stdc++.h>
using namespace std;
set<int>a;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int w;
		cin>>w;
		a.insert(w);
	}
	int ans=-1;
	if(a.size()<2){
		puts("-1");
	}
	else if(a.size()==2){
		puts("0");
	}
	else{
		for(auto it=a.begin();it!=a.end();it++){
			if(it==a.begin()){
				continue;
			}
			ans=max(ans,*it-*(--it));
			++it;
		}
		auto it=a.end();
		it--;
		it--;
		it--;
		cout<<max(ans,*it);
	}
	return 0;
}

hank:

3
1000 10 3
2024/10/12 08:18
加载中...