日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

结构体+sort方法

發布時間:2023/12/9 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 结构体+sort方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

昨天做了一道簡單但很麻煩的題,我只能想到結構體,并用了STL的sort方法解決了它.不過從中有許多細節問題.

題目:

?

Problem Description

Lcy wanted to choose 50 ACMers from m players to join HDU-ACM team.
He made n competitions , and now is your task to make the ranklist.
Here’re some instructions :
Effective score : the sum of the best n-2 competitions’ score.
One’s score in one competition : number of problems he(or she) solved divided the sum of problems all players solved.

The ranklist is made , of course , by the effective score , what if some players have the same score ?Follow these rules : girls always come first , same again and younger first , again ? In lexicographic order.

Input

For each case , two integers in the first line : n (3<= n <= 10)and m(m<=1000)
The next m lines are someone’s information :
name , sex (F,M), grade and n integer numbers which means one’s number of solved problem in the ith competition.

Output

Output the first fifty players in order . Output all if m<50.

Sample Input

3 2 WXL F 08 3 4 5 HH M 08 3 4 5

Sample Output

WXL HH

?

代碼如下:

?

Code
#include<iostream>
#include
<algorithm>
#include
<string>
using?namespace?std;
bool?dic(char?*a,?char?*b)
{
????
int?p;
????p
=strcmp(a,b);
????
if(p>0)
????????
return?false;
????
else?return?true;
}

typedef?
struct
{
????
char?name[21];
????
char?sex;
????
int?grade;
????
float?score;
????
int?s[11];
}
node;
node?a[
1001];

bool?comp(node?a,?node?b)
{
????
if(a.score?!=?b.score)
????????
return?a.score>b.score;
????
else
????
{
????????
if(a.sex?!=?b.sex)
????????????
return?a.sex<b.sex;
????????
else?if(a.grade?!=?b.grade)
????????????
return?a.grade>b.grade;
????????
else
????????????
return?dic(a.name,b.name);
????}

}


int?main()
{
????
int?n,m,i,j,k;
????
float?b[11],p,f[11];
????
while(scanf("%d%d",&n,&m)!=EOF)
????
{
????????
for(i=0;?i<m;?i++)
????????
{
????????????getchar();
????????????scanf(
"%s?%c?%d",&a[i].name,&a[i].sex,&a[i].grade);
????????????
for(j=0;?j<n;?j++)
????????????
{
????????????????scanf(
"%d",&a[i].s[j]);
????????????}

????????}


????????
for(i=0;?i<n;?i++)
????????
{
????????????b[i]
=0;
????????????
for(j=0;?j<m;?j++)
????????????
{
????????????????b[i]
+=a[j].s[i];
????????????}

????????}

????????
for(i=0;?i<m;?i++)
????????
{
????????????a[i].score
=0;
????????????
for(j=0;?j<n;?j++)
????????????
{
????????????????p
=(float)a[i].s[j]/b[j];
????????????????f[j]
=p;
????????????}

????????????sort(f,f
+n);
????????????
for(k=n-1;?k>1;?k--)
????????????
{
????????????????a[i].score
+=f[k];
????????????}

????????}

????????sort(a,a
+m,comp);
????????
for(i=0;?i<m;?i++)
????????
{
????????????cout
<<a[i].name<<endl;
????????????
if(i==49)break;
????????}

????}

????
return?0;
}

轉載于:https://www.cnblogs.com/chenjunyu/archive/2009/05/04/1448920.html

總結

以上是生活随笔為你收集整理的结构体+sort方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。