题目描述
给定一个数组,输出其中第四小的整数(相等的整数只计算一次)。
输入
第一行一个正整数,4<=n<=1000.
第二行个整数,正整数的值域为[-109,109].
第二行个整数,正整数的值域为[-109,109].
输出
一行一个整数。
样例输入 Copy
7
3 3 2 0 -1 -1 8
样例输出 Copy
3
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main (){
int n;
cin>>n;
int a[n];
int t=0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int j=0;j<n;j++){
if (a[j]!=a[j+1]){
t=t+1;
}
if(t==4){
cout<<a[j]<<endl;
break; }
}
return 0;
}