这题,乍一看,呵,就这??
于是我就兴致勃勃的写了,结果也没有让我失望,9.0/10.0,就差一分,先上9分代码,想了30多分钟,还是想不出哪里出问题了,上代码!
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i,a[100005],max=2147483649,min=-2147483649;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n;i++){
if(min > a[i]) min=a[i];
if(max < a[i]) max=a[i];
}
cout<<min<<" "<<max;
return 0;
}
ta的结果是这样的。。
花式疑惑了30多分钟,隔壁的小孩都解出来了。。
于是,我就改了一下max和min的初始值,没想到,就对了!!上代码!
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i,a[100005],max,min;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
max=a[1];
min=a[1];
for(i=1;i<=n;i++){
if(min > a[i]) min=a[i];
if(max < a[i]) max=a[i];
}
cout<<min<<" "<<max;
return 0;
}
试题链接:https://vjudge.net/contest/390063#problem/C