#include <iostream>
using namespace std;
#define maxn 10001
int as[maxn];
int main()
{
int t,a,b,c,i;
cin>>t;
while(t--)
{
cin>>a;
for(i =1 ; i<=a; i++)
cin>>as[i];
for( i = 1;i<=a-1;i++)
for(int j = 1;j<=a-1;j++)
if(as[j]<as[j+1])swap(as[j],as[j+1]);
c=as[1];
for(i=1;i<=a-1;i++)
{
if(c>=(as[i]-as[i+1]))
{c=as[i]-as[i+1];
}
}
cout<<c<<endl;
}
return 0;
}
最近,很懒。就,玩玩玩。
然后,没有做太多的题。但是,第一次,在一场比赛里,做出来了两道题。还是压哨。
心态控制的是真的好,因为没有比我更笨的。就,极限赌博就好了。
但是,第一次两个小时的比赛做出两道,中途刷视频刷了一个小时。
比赛结束最后一分钟,我改成c=as【1】;从for拿了出来,后来想想,是最后一次的if不执行直接c==煤改之前的数
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
cin >> test;
for (int tt = 0; tt < test; tt++) {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
sort(a.begin(), a.end());
int result = a[n - 1] - a[0];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
result = min(result, a[j] - a[i]);
}
}
cout << result << endl;
}
return 0;
}
官方就很简单,用vector。排序,双重循环找最小,整体思路和我一样
结课了。可以写自己的博客了,就很cool。可以干点好玩的了。下周要换一个总结名字。里程碑吧算是。
刚用fu文本编辑器,还是不是很会用。okok。下周再见。