CCF CSP 201903-01 小中大

 

滿分代碼:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main ()
{    int n;
     cin>>n;
     int a[n];
     for(int i=0;i<n;i++)
        cin>>a[i];
     if(a[0]>=a[n-1])
     {
         cout<<a[0]<<" ";
         if(n%2==1)
           cout<<a[n/2]<<" ";
          else
          {
              double z=(a[n/2]+a[n/2-1])/2.0;
              if(z==(int)z)
                cout<<(int)z<<" ";
              else
                cout<<fixed<<setprecision(1)<<z<<" ";
          }
          cout<<a[n-1];

     }
     else
     {
          cout<<a[n-1]<<" ";
         if(n%2==1)
           cout<<a[n/2]<<" ";
          else
          {
              double z=(a[n/2]+a[n/2-1])/2.0;
              if(z==(int)z)
                cout<<(int)z<<" ";
              else
                cout<<fixed<<setprecision(1)<<z<<" ";
          }
          cout<<a[0];

     }

    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章