题目1014:排名-----------------------此题是一个坑----------------------------------结构体还是用纯c语言不要夹杂c++

此题的思路简单,从上到下进行模拟,该定义的定义,该输入的输入,该输出的输出;

最重要的是,该用结构体的一定要用结构体!!!!!!!

此题的坑在于,我用c++写的代码怎么都是WA,但是我只是简单的把输入输出换成c语言printf和scanf,就AC掉,,,,,,无天理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<stdio.h>
  
#include<string.h>
#include<algorithm>
using namespace std;
 
struct student
{
    char num[100];
    int sum_s;
};
int cmp(const void *a,const void *b)
{
    student at=*(student*)a;
    student bt=*(student*)b;
    if (bt.sum_s==at.sum_s)
    return strcmp(at.num,bt.num);
    //return at.num.compare(bt.num);    
    else return bt.sum_s-at.sum_s;
}
int queue[6];
int main()
{
    student stu[1000];
    int N,M,G;
      
    while(scanf("%d",&N)!=EOF)
     {
        if(N==0) break;
        else
        {
        scanf("%d %d",&M,&G);  
        int s_count;   
        int i=0,j=0;
        for (i=1;i<=M;i++)
          scanf("%d",&queue[i]);
        for (i=0;i<N;i++)
        {
            scanf("%s %d",&stu[i].num,&s_count);
            int tem_sum=0;
            int tem;
            stu[i].sum_s=0;
            for (j=0;j<s_count;j++)
            {
               scanf("%d",&tem);
               tem_sum+=queue[tem];
            }
            stu[i].sum_s=tem_sum;
        }
        qsort(stu,N,sizeof(student),cmp);
        int count=0;
        for (i=0;i<N;i++)
        {
            if (stu[i].sum_s>=G)
                count++;   
        }
         printf("%d\n",count); 
         for (i=0;i<N;i++)
                if (stu[i].sum_s>=G)
            printf("%s %d\n",&stu[i].num,stu[i].sum_s); 
        
    }
    return 0;  
}

  

posted @   贱人郭  阅读(186)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示