Accelerated C 習題 第3章

2021-09-29 11:40:09 字數 3385 閱讀 8036

# include

# include

#include

#include

#include

# include

using

namespace std;

intmain()

typedef vector<

double

>

::size_type vec_sz;

vec_sz size = homework.

size()

;//判斷homework是否為空

if(size ==0)

//排序

sort

(homework.

begin()

, homework.

end())

;double median;

median = size %2==

0?(homework[size /2]

+ homework[size /2-

1])/

2: homework[size /2]

;//計算成績,設定精度

中值是乙個可將數值集合劃分為相等的上下兩部分的數值。對於有限的數集,通過把所有的值高低排序後找出正中間的乙個作為中位數。中間點取決於所有的數值。

由此可知,如果任何乙個我們已經讀到的值被丟棄,則會改變原先中間點的位置,這樣就得不出準確的中值。

#include

#include

#include

#include

using

namespace std;

intmain()

sort

(integers.

begin()

, integers.

end())

;typedef vector<

int>

::size_type vec_size;

vec_size size;

//集合總長度

size = integers.

size()

;//判斷是否為空

if(size ==0)

//集合中間位置

int mid = size /2;

//集合四分之一位置

}//不同的單詞if(

!same)

}for

(vec_size i =

0; i != words.

size()

;++i)

}

#include

< iostream>

#include

#include

#include

using

namespace std;

intmain()

//shortest_sz == 0這個一定要寫 不然 找不到最小的那個

if(shortest_sz ==

0|| str.

size()

< shortest_sz)

} cout <<

"最長的字元:"

<< longest << endl;

cout << longest_sz << endl;

cout<<

"最短的字元:"

Accelerated C 習題 第0章

include using namespace std intmain this is a quote,and this is a backlash.include using namespace std intmain include using namespace std intmain inc...

Accelerated C 習題解答 第1章

ex.1 01 include include includeint main std cout std string name std cin name std cout include include includeint main std cout std string name std ci...

Accelerated C 習題解答 第3章

部分習題參考了網上已有的解答 ex.3 0 include include include include include include includeusing std cin using std cout using std endl using std string using std ve...