牛客網 KY117 奧運排序問題

2021-10-19 16:24:25 字數 1342 閱讀 5329

最直觀的解法就是四個排序全部進行一次,記錄最好的一次輸出,解法如下:

#include

#include

#include

using

namespace std;

class

country

;bool

cmp_gold

(country a, country b)

bool

cmp_medal

(country a, country b)

bool

cmp_gp

(country a, country b)

bool

cmp_mp

(country a, country b)

bool

cmp_num

(country a, country b)

country all[

250]

;int

main()

for(

int i =

0; i < m;

++i)

sort

(all, all + n, cmp_gold)

;//按金牌總數排序

int k =1;

for(

int i =

0; i < n;

++i)

else

}sort

(all, all + n, cmp_medal)

;//按獎牌總數排序

k =1;

for(

int i =

0; i < n;

++i)

else

}sort

(all, all + n, cmp_gp)

;//按金牌人口比例排序

k =1;

for(

int i =

0; i < n;

++i)

else

}sort

(all, all + n, cmp_mp)

;//按獎牌人口比例排序

k =1;

for(

int i =

0; i < n;

++i)

else

}sort

(all, all + n, cmp_num)

;//再按國家順序排序

for(

int i =

0; i < n;

++i)

} cout << r <<

":"<< method << endl;}}

}}

牛客網KY115 字尾子串排序

對於乙個字串,將其字尾子串進行排序,例如grain 其子串有 grain rain ain in n 然後對各子串按字典順序排序,即 ain,grain,in,n,rain 輸入描述 每個案例為一行字串。輸出描述 將子串排序輸出 輸入 grain輸出 ain graininn rain includ...

牛客網 KY194樹查詢

ky194 樹查詢 有一棵樹,輸出某一深度的所有節點,有則輸出這些節點,無則輸出empty。該樹是完全二叉樹。輸入有多組資料。每組輸入乙個n 1 n 1000 然後將樹中的這n個節點依次輸入,再輸入乙個d代表深度。輸出該樹中第d層得所有節點,節點間用空格隔開,最後乙個節點後沒有空格。示例1 4 1 ...

牛客網 KY45 skew數

在 skew binary 表示中,第 k 位的值 x k 表示 x k 2 k 1 1 每個位上的可能數字是 0 或 1,最後面乙個非零位可以是 2,例如,10120 skew 1 2 5 1 0 2 4 1 1 2 3 1 2 2 2 1 0 2 1 1 31 0 7 6 0 44。前十個 sk...