中间的数(若已经排好序)
生活随笔
收集整理的這篇文章主要介紹了
中间的数(若已经排好序)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
描述:
奇數(shù)個,輸出中間那個
偶數(shù)個,輸出中間那倆
?
代碼:
#include<iostream>
using namespace std;
int main()
{
??? int *a;
??? int n;
??? cin>>n;
??? a=new int[n];
??? for(int i=0; i<n; i++)
??????? cin>>a[i];
??? if(n%2==1)
??????? cout<<a[(n-1)/2]<<endl;
??? else if(n>=2)
??????? cout<<a[(n-1)/2]<<a[(n-1)/2+1]<<endl;
??????? delete []a;//這個必須有
??? return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/TogetherLaugh/p/6545125.html
總結(jié)
以上是生活随笔為你收集整理的中间的数(若已经排好序)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Problem B: 字符类的封装
- 下一篇: description方法