CSP认证201712-1

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1000+10;
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int minsub = 10000;  //设定两个不超过10000的正整数的差值最小为10000,因为差值或者其绝对值不会超过这个值 
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int sub = a[i]-a[j];   //计算差值 
			if(abs(sub)<=minsub)   //与设定的最小差值比较 
			{
				minsub = abs(sub);  //满足条件,更新最小差值 
			}
		}
	}
	printf("%d\n",minsub);
	return 0;
}
 
 
 

 

posted @   克隆窝  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示