zoukankan      html  css  js  c++  java
  • hdu 2093 考试排名使用 sscanf () 用于判断输入有没有括号

    #include <cstdio>
    #include 
    <cstdlib>
    #include 
    <cstring>
    #define    MAX 1000

    typedef 
    struct
    {
        
    char    name[11];
        
    int    sum;
        
    int    total;
    }credit;

    int cmp(const void *a, const void *b)
    {
        
    if ((*(credit *)a).total != (*(credit *)b).total)
            
    return (*(credit *)a).total - (*(credit *)b).total;
        
    else if ((*(credit *)b).sum != (*(credit *)a).sum)
            
    return (*(credit *)b).sum - (*(credit *)a).sum;
        
    else
            
    return strcmp((*(credit *)b).name, (*(credit *)a).name);
    }

    int main()
    {
        
    int    res, t, f;
        
    int    i, n, m, j;
        
    char    style[10];
        credit    c[MAX] 
    = {0};
        scanf ( 
    "%d%d"&n, &m );
        
    for ( i = 0; scanf("%s", c[i].name) != EOF; i++ )
        {
              
    for ( j = 0; j < n; j++ )
              {
                    scanf ( 
    "%s", style );
                    res 
    = sscanf(style, "%d(%d)"&t, &f );
                    
    if ( res == 2 )
                    {
                        c[i].total
    ++;
                        c[i].sum 
    += t + f * m;
                    }
                    
    else if (res == 1 && t > 0)
                    {
                        c[i].total
    ++;
                        c[i].sum 
    += t;
                    }
              }
        }

        qsort(c, i, 
    sizeof(credit), cmp);
        
    for ( i--; i >= 0; i-- )
        {
             printf(
    "%-10s %2d %4d\n", c[i].name, c[i].total, c[i].sum);
        }
        
    return 0;

    } 

  • 相关阅读:
    标题栏外区域拖动窗体
    搜索引擎技术核心揭密
    用C#实现木马程序(转载)
    DotNet里的控件数组
    RECORDNUMBER应用之控制每页显示行数及隔行换色
    搜索引擎技术学习
    VB里面操作Excel(居然比C#强)
    第三代搜索引擎技术与P2P
    C# 用API播放声音
    如何判断ExecuteScalar()得到的结果是否有记录
  • 原文地址:https://www.cnblogs.com/anderson0/p/2040084.html
Copyright © 2011-2022 走看看