題目1007 奧運排序問題(結構體排序)

2022-04-12 08:41:58 字數 1160 閱讀 9084

每個國家根據金牌總數、獎牌總數、金牌人口比例、獎牌人口比例會有四種排序,找到最佳排名。

我們用結構體把每個國家的資訊存下來,在進行處理。根據四種不同的排序方式計算得出四種排名。

注意:記得最後再把國家按照最大是的順序排回來(事先用id屬性記下序號)。

有關於sort函式使用詳解請參考:

//

//created by alvinzh on 2017/4/29.

////

#include #include

#include

#include

using

namespace

std;

typedef

struct

country

}country;

vector

all;

vector

c;bool

cmp1(country a,country b)

bool

cmp2(country a,country b)

bool

c***(country a,country b)

bool

cmp4(country a,country b)

bool

cmp5(country a,country b)

intmain()

for(int i=0;i)

sort(c.begin(),c.end(),cmp1);

for(int i=0;i)

sort(c.begin(),c.end(),cmp2);

for(int i=0;i)

sort(c.begin(),c.end(),c***);

for(int i=0;i)

sort(c.begin(),c.end(),cmp4);

for(int i=0;i)

sort(c.begin(),c.end(),cmp5);

for(int k=0;k)

}printf(

"%d:%d\n

",rank,choice);

}printf("\n

");}

}

出處: 

本人github:

題目1007 奧運排序問題

題目1007 奧運排序問題 時間限制 1 秒 記憶體限制 32 兆 特殊判題 否 提交 3180 解決 669 題目描述 按要求,給國家進行排名。輸入 有多組資料。第一行給出國家數n,要求排名的國家數m,國家號從0到n 1。第二行開始的n行給定國家或地區的奧運金牌數,獎牌數,人口數 百萬 接下來一行...

題目1007 奧運排序問題

時間限制 1 秒 記憶體限制 32 兆 特殊判題 否 提交 9031 解決 1952 題目描述 按要求,給國家進行排名。輸入 有多組資料。第一行給出國家數n,要求排名的國家數m,國家號從0到n 1。第二行開始的n行給定國家或地區的奧運金牌數,獎牌數,人口數 百萬 接下來一行給出m個國家號。輸出 排序...

題目1007 奧運排序問題

題目1007 奧運排序問題 時間限制 1 秒 記憶體限制 32 兆 特殊判題 否 提交 3180 解決 669 題目描述 按要求,給國家進行排名。輸入 有多組資料。第一行給出國家數n,要求排名的國家數m,國家號從0到n 1。第二行開始的n行給定國家或地區的奧運金牌數,獎牌數,人口數 百萬 接下來一行...