zoukankan      html  css  js  c++  java
  • hdu 1236 排名

    http://acm.hdu.edu.cn/showproblem.php?pid=1236

    自己写的comp,终于勉强算是掌握sort()了...囧...继续努力~

     1 #include<stdio.h>
     2 #include<string.h> 
     3 #include<algorithm>
     4 using namespace std;
     5 struct St
     6 {
     7     char s[30];
     8     int sum,p;
     9 };
    10 bool comp(struct St a,struct St b)
    11 {
    12     if(a.sum!=b.sum)
    13       return a.sum>b.sum;  //成绩降序 
    14     else if(strcmp(a.s,b.s)<0)
    15       return   true;
    16       else return false;   //学号升序 
    17 }
    18 int main()
    19 {
    20     int n;
    21     while(~scanf("%d",&n)&&n)
    22     {
    23         int m ,g,a[20],i,j,k,x,num=0;
    24         struct St b[1000];
    25         scanf("%d%d",&m,&g);
    26     //    printf("%d%d%d
    ",n,m,g);
    27         for(i=0;i<m;i++)
    28           scanf("%d",&a[i]);
    29         for(i=0;i<n;i++)
    30         {
    31             scanf("%s",&b[i].s);b[i].sum=0,b[i].p=0;
    32     //        printf("%s",b[i].s);
    33             scanf("%d",&k);
    34             for(j=0;j<k;j++)
    35             {
    36                 scanf("%d",&x);
    37                 b[i].sum+=a[x-1];
    38             }
    39             if(b[i].sum>=g)
    40               {num++;b[i].p=1;}
    41         }  
    42         printf("%d
    ",num);
    43         sort(b,b+n,comp);
    44         for(i=0;i<n;i++)
    45         if(b[i].p==1)
    46         printf("%s %d
    ",b[i].s,b[i].sum);
    47     }
    48 }
  • 相关阅读:
    模拟22
    模拟21
    模拟20
    模拟19
    晚测11
    Redis 内存模型
    Redis AOF重写
    基础省选题选做
    八年级上 期中考试祭
    P2049 魔术棋子 题解
  • 原文地址:https://www.cnblogs.com/xurenwen/p/3866294.html
Copyright © 2011-2022 走看看