
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
啊啊啊,折磨了我三个多小时的题目。。。还是细节问题啊。。
上代码吧。。。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
int ac; // AC 数
int time; // 时间
char name[15];// 名字
};
node f[10000];
bool cmp(node a,node b) //排序
{
if(a.ac==b.ac)
{
if(a.time==b.time) //AC数和时间都等
return strcmp(a.name,b.name)<0;// 按字典的名字由小到大
return a.time<b.time;// AC数相等时间不等,按时间升序。
}
return a.ac>b.ac;// AC数降序排。
}
int main()
{
int j,i,pp,n,m;
scanf("%d%d",&n,&m);
i=0; //令i=0,代表第一个人
while(scanf("%s",f[i].name)!=EOF)// 输入第i个人的名字
{
f[i].ac=f[i].time=0;// 令第i个人的AC数和时间等于0
for(j=0;j<n;j++)// n是题目数。
{
scanf("%d",&pp); //输入数字
if(pp<=0) //如果小于0的话,代表没做出来。则不管
continue;
f[i].ac++; //做出来代表1A,第i个人的AC数加一。
f[i].time+=pp;//加上所用的时间。
if(getchar()=='(') //从键盘上输入一个字符等于括号的话,代表这题做出来了,但是有错过。
scanf("%d",&pp),//输入做错的次数。
f[i].time+=pp*m,//加上罚时的时间,罚时时间为m*做错的次数。
getchar();
}
i++; //加一个i,考虑下一个人的情况。
}
sort(f,f+i,cmp);// 做好上面之后,排序
for(j=0;j<i;j++)
printf("%-10s %2d %4d\n",f[j].name,f[j].ac,f[j].time);//输出。
return 0;
}
原文地址:http://blog.csdn.net/sky_miange/article/details/42319199