解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <string.h>
typedef struct Person
{
char name[20];
char num[12][5];
int count;
int time;
char count1[10];
char time1[10];
}Per;
int main(void)
{
int timu, fashi, sum, l;
while (scanf("%d%d", &timu, &fashi) != EOF)
{
int length = 0, i;
Per d[100];
while (scanf("%s", d[length].name) != EOF)
{
for (i = 0;i < timu;i++)
scanf("%s", d[length].num[i]);
length++;
}
for (i = 0;i < length;i++)
{
int j;
d[i].time = 0;
d[i].count = 0;
for (j = 0;j < timu;j++)
{
if (d[i].num[j][0] == '-' || d[i].num[j][0] == '0')
continue;
else
{
char *p = d[i].num[j];
int flag = 0;
d[i].count++;
while (*p != '\0')
{
if (*p == '(')
{
flag = 1;
*p = '\0';
break;
}
p++;
}
if (flag == 1)
{
if (*(p + 2) == ')')
d[i].time = d[i].time + fashi*(*(p + 1) - '0');
else
{
int sum;
sum = (*(p + 1) - '0') * 10 + (*(p + 1) - '0');
d[i].time = d[i].time + fashi*sum;
}
}
p = d[i].num[j];
if (*(p + 1) == '\0')
d[i].time = d[i].time + *p - '0';
else if (*(p + 2) == '\0')
{
int sum;
sum = (*p - '0') * 10;
sum = sum + *(p + 1) - '0';
d[i].time = d[i].time + sum;
}
else
{
int sum;
sum = (*p - '0') * 100;
sum = sum + (*(p + 1) - '0') * 10;
sum = sum + (*(p + 2) - '0');
d[i].time = d[i].time + sum;
}
}
}
d[i].count1[0] = d[i].count + '0';
d[i].count1[1] = '\0';
sum = d[i].time;
l = 9;
d[i].time1[l--] = '\0';
if (sum == 0)
d[i].time1[l--] = '0';
else
{
while (sum != 0)
{
d[i].time1[l--] = sum % 10 + '0';
sum = sum / 10;
}
}
while (l >= 0)
d[i].time1[l--] = '#';
}
for (i = 0;i < length - 1;i++)
{
int j;
for (j = i + 1;j < length;j++)
{
Per temp;
if (d[i].count < d[j].count)
{
temp = d[i];
d[i] = d[j];
d[j] = temp;
}
else if (d[i].count == d[j].count)
{
if (d[i].time > d[j].time)
{
temp = d[i];
d[i] = d[j];
d[j] = temp;
}
else if (d[i].time == d[j].time)
{
if (strcmp(d[i].name, d[j].name)>0)
{
temp = d[i];
d[i] = d[j];
d[j] = temp;
}
}
}
}
}
for (i = 0;i < length;i++)
{
l = 0;
while (d[i].time1[l] == '#')
l++;
printf("%-10s %2s %4s\n", d[i].name, d[i].count1, &d[i].time1[l]);
}
}
return 0;
}
0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复