hdu 2093 考试排名使用 sscanf () 用于判断输入有没有括号
2011-05-07 22:51
453 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2093#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;
}
#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;
}
相关文章推荐
- hdu 2093 考试排名(sscanf)
- hdu 2206IP的计算(sscanf的使用 & 字符串判断处理)
- HDU 2093 考试排名
- HDU 2093 考试排名
- Hdu 2093 考试排名【字符串】
- HDU 2093考试排名(结构体多关键字排序+字符串处理)
- HDU 2093考试排名
- hdu 2093 考试排名
- HDU--杭电--2093--考试排名--结构体排序
- 【HDU】2093 - 考试排名(结构体排序)
- hdu 2093 考试排名
- HDU 2093 考试排名
- HDU 2093 考试排名【结构体排序】
- HDU 2093 (考试排名)
- HDU 2093 考试排名 (结构体+排序+简单但麻烦)
- HDU 杭电 acm-2093-考试排名
- HDU 2093 考试排名
- HDU 2093 考试排名
- HDU 2093(考试排名)解题纠错
- 【HDU 2093】考试排名