标签:des style http color java os io strong
/*
题目大意:求按分数的排名次序和求出分数在G以上的人数。
解题思路:见下面的注释
难点详解:结构体数组的每一个元素都具有相同的结构体类型。在实际应用中,经常用结构体数组来表示具有相同数据结构的一个群体。如一个班的学生档案,一个车间职工的工资表等。
关键点:二级结构体排序
解题人:lingnichong
解题时间:2014/08/06 10:35
解题感受:就是结构体的排序,还有就是看好题意
*/
4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0
3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20HintHuge input, scanf is recommended.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct per
{
char number[25];
int total;
}stu[1100];
int cmp(per x,per y)//二级结构体排序
{
if(x.total != y.total)
return x.total > y.total;
return strcmp(x.number,y.number) < 0;
}
int main()
{
int N,M,G;
int i,j,score[12];
int n,sum,m;
int k;
while(scanf("%d", &N), N)
{
k=0;
memset(stu,0,sizeof(stu));
memset(score,0,sizeof(score));
scanf("%d%d", &M, &G);
for(i = 1; i <= M; i++)//要根据题号来给相应的题赋予分数
scanf("%d", &score[i]);
getchar();//下一个是输入字符的所以要用getchar();
for(i = 0; i < N; i++)
{
scanf("%s", stu[i].number);
sum=0;
scanf("%d", &n);
for(j = 0; j < n; j++)//求出每个人的总得分
{
scanf("%d", &m);
sum+=score[m];
}
stu[i].total=sum;
}
for(i = 0; i < N; i++)//算出分数大于等于G的人数
{
if(stu[i].total>=G)
k++;
}
sort(stu,stu+N,cmp);//排序
// for(i = 0; i < N; i++)
// printf("%s %d\n",stu[i].number,stu[i].total);
printf("%d\n", k);
for(i = 0; i < N; i++)
{
if(stu[i].total>=G)
printf("%s %d\n",stu[i].number,stu[i].total);
}
}
return 0;
}
标签:des style http color java os io strong
原文地址:http://blog.csdn.net/qq_16767427/article/details/38397341