解题思路:
注意事项:
参考代码:
#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语言训练-8除不尽的数 (C语言代码)暴力解法,答案只有一个,直接输出就好了浏览:1049 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:677 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:701 |
汽水瓶 (C语言代码)浏览:664 |
C语言训练-斐波纳契数列 (C语言代码)浏览:1286 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:553 |
【亲和数】 (C语言代码)浏览:590 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1270 |
【简单计算】 (C语言代码)浏览:642 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:572 |