zoukankan      html  css  js  c++  java
  • 团体程序设计天梯赛PTA L2-021点赞狂魔

     分析:难点在结构体排序?emm...这题没有难点下一题。

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<vector>
     4 #include<map>
     5 #include<set>
     6 #include<algorithm>
     7 using namespace std;
     8 struct node
     9 {
    10     char name[30];
    11     double ave;
    12     set<int>q;
    13     map<int,int>mp;
    14     int sum,kind,all;
    15 }no[105];
    16 bool cmp(node a,node b)
    17 {
    18 
    19     if(a.kind == b.kind)
    20     {
    21         return a.ave<b.ave;
    22     }
    23         return a.kind > b.kind;
    24 }
    25 int main()
    26 {
    27     int n,a;
    28     scanf("%d",&n);
    29     for(int i = 1; i <= n; i ++)
    30     {
    31         scanf("%s%d",no[i].name,&no[i].all);
    32         for(int j = 1; j <= no[i].all; j ++)
    33         {
    34             scanf("%d",&a);
    35             no[i].q.insert(a);
    36             no[i].mp[a]++;
    37             no[i].sum+=no[i].mp[a];
    38         }
    39         no[i].kind=no[i].q.size();
    40         no[i].ave=no[i].sum/(double)no[i].all;
    41     }
    42     sort(no+1,no+n+1,cmp);
    43     if(n==1)printf("%s - -",no[1].name);
    44     else if(n==2)printf("%s %s -",no[1].name,no[2].name);
    45     else
    46     {
    47         printf("%s %s %s",no[1].name,no[2].name,no[3].name);
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    ABAP中COLLECT的用法
    中文字符串提交乱码的解决方法
    我的Ubuntu系统
    SAP消息呈现
    ASP.NET博客站点全静态化的困扰
    JS利用函数修改全局变量
    让电脑速度增快几倍的法宝
    我的Ubuntu门派
    给老乡买本本的经历
    多事之秋
  • 原文地址:https://www.cnblogs.com/dark-ming/p/13871328.html
Copyright © 2011-2022 走看看