shallowcmz


私信TA

用户名:shallowcmz

访问量:42415

签 名:

行者常至,为者常成

等  级
排  名 230
经  验 6214
参赛次数 1
文章发表 57
年  龄 18
在职情况 学生
学  校 东莞理工学院
专  业 软件工程

  自我简介:

TA的其他文章

解题思路:





注意事项:





参考代码:

#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 人评分

新上线《蓝桥杯辅导》课程,近五年的蓝桥杯省赛与国赛真题都有,从读题开始理解题意、梳理思路、实现代码再提交评测全过程,可有效提升获奖比例甚至进国赛!课程介绍、试听请猛击这里

  评论区

  • «
  • »