#include<iostream> #include<algorithm> using namespace std; int main() { int i=0,b[11],n,s; cin>>n; while(n--) { cin>>s; for(i=0;i<10;i++) cin>>b[i]; sort(b,b+10); cout<<s<<" "<<b[7]<<endl; }
return 0; }
思路二:
#include<iostream> #include<algorithm> using namespace std;
int b[11]; int main() { int w; cin>>w; while(w--) { int n=10,ss; cin>>ss; int i=0; while(i<n) { cin>>b[i++]; } nth_element(b,b+7,b+10); cout<<ss<<" "<<b[7]<<endl;; } }