#include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; int main() { int n; cin>>n; vector<int> v; for(int i=0;i<n;i++) { int temp; cin>>temp; v.push_back(temp); } double mid; int midint; int a1=v[0],a2=v[v.size()-1]; if(n%2==0) { //if((v[(v.size()-1)/2]%2!=0&&v[(v.size()-1)/2+1]%2==0)||v[(v.size()-1)/2]%2==0&&v[(v.size()-1)/2+1]%2!=0) mid=(v[(v.size()-1)/2]+v[(v.size()-1)/2+1])*1.0/2;// 0 1 2 3 //else //midint } else { midint=(v.at(v.size()/2));// 0 1 2 } if(n%2==0) { int base=1; if(fabs(mid-(int)mid)<1e-9) base=0; if(a1<a2) cout<<a2<<" "<<setiosflags(ios::fixed)<<setprecision(base)<<mid<<" "<<a1<<endl; else cout<<a1<<" "<<setiosflags(ios::fixed)<<setprecision(base)<<mid<<" "<<a2<<endl; } else { if(a1<a2) cout<<a2<<" "<<midint<<" "<<a1<<endl; else cout<<a1<<" "<<midint<<" "<<a2<<endl; } }
原文:https://www.cnblogs.com/-Asurada-/p/14386517.html