zoukankan      html  css  js  c++  java
  • 杭电1.3.6考试排名

     1 /*杭电1.3.6考试排名*/
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 typedef struct person
     6 {
     7     char name[11];
     8     int acnum;   //做对了几题
     9     int timescore;   //时间分-越多越不好
    10 }Person;
    11 
    12 int cmp(const void * a,const void *b)
    13 {
    14     Person * c=(Person *)a;
    15     Person * d=(Person *)b;
    16     if (c->acnum!=d->acnum)  //先按ac数
    17     {
    18         return d->acnum-c->acnum;
    19     }
    20     else
    21     {
    22          if (c->timescore!=d->timescore)   //再按时间数
    23          {
    24              return c->timescore-d->timescore;
    25          }
    26          else   //名字
    27          {
    28              return strcmp(c->name,d->name);
    29          }
    30     }
    31 }
    32 
    33 Person arrperson[100];   //假设最多100人
    34 
    35 int main(void)
    36 {
    37     int n,m;
    38     int pernum=0;   //记录输入人数
    39     int i;
    40     scanf("%d %d",&n,&m);
    41     while (scanf("%s",arrperson[pernum].name)!=EOF)
    42     {
    43         int errotime=0,timescore=0,ac=0;   //提交错的次数,时间分(未加错误的罚分),ac题数
    44         char chartemp[8];   //装每个数字--用字符串处理
    45         char * p;
    46         for (i=0;i<n;i++)   //对每题的处理
    47         {
    48             scanf("%s",chartemp);
    49             p=strchr(chartemp,'(');   //在这个字符串中找有没有括号------------------------------------------------------------------
    50             if (p)   //不是null,就是有括号
    51             {
    52                 int shuzi1,shuzi2;    //前为时间,后卫错次数
    53                 sscanf(chartemp,"%d(%d)",&shuzi1,&shuzi2);   //从字符串中提取数字--------------------------------------------------
    54                 timescore+=shuzi1;
    55                 errotime+=shuzi2;
    56                 ac++;
    57             }
    58             else   //是null,就是没有括号----直接得到数字
    59             {
    60                 int shuzi;
    61                 sscanf(chartemp,"%d",&shuzi);
    62                 if (shuzi>0)   //数字<=零不管了,都是没有通过
    63                 {
    64                     timescore+=shuzi;
    65                     ac++;
    66                 }
    67             }
    68         }
    69         timescore=timescore+errotime*m;
    70         arrperson[pernum].timescore=timescore;
    71         arrperson[pernum].acnum=ac;
    72         pernum++;   //人数加
    73     }
    74     qsort(arrperson,pernum,sizeof(Person),cmp);
    75     for (i=0;i<pernum;i++)
    76     {
    77         printf("%-10s %2d %4d\n",arrperson[i].name,arrperson[i].acnum,arrperson[i].timescore);
    78     }
    79     getchar();
    80     return 0;
    81 }
  • 相关阅读:
    数据库新增“自动添加”类字段 auto_now_add 如何不影响之前数据
    django rest framework serializer中获取request中user方法
    django Table doesn't exist
    python 日期换算星期 蔡勒公式
    python pdfkit html转pdf响应式轮子 django例
    Python Excel 多sheet 多条数据 自定义写入
    Python 爬虫 Vimeo视频下载链接
    Python 快速排序 算法
    jvm内存模型
    JMV的学习
  • 原文地址:https://www.cnblogs.com/jiayith/p/2996403.html
Copyright © 2011-2022 走看看