To be honest,I don’t really want to blog this article.The first reason is that I am not much sure what topic of it should be named ,but finally I call it “weird”.Oh,it is strange.And the second reason why I reckon this is that there are many blogs on this subject.But I have to still say something.
Here are three pictures to describe this problem:
I think I’d better paste the test data:
Sample Input
8 20
GuGuDong 96 -3 40(3) 0 0 1 -8 0
hrz 107 67 -3 0 0 82 0 0
TT 120(3) 30 10(1) -3 0 47 21(2) -2
OMRailgun 0 -99 -8 0 -666 -10086 0 -9999996
yjq -2 37(2) 13 -1 0 113(2) 79(1) -1
Zjm 0 0 57(5) 0 0 99(3) -7 0
A little bit of a mess,isn’t it?
And the next you can see the code:
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
using std::setw;
struct student{
char name[20];//姓名
int time;//时间
int ac;//做出的题
};
struct student stu[10000];
bool cmp(student s,student t){//比较函数,用于sort排序
if(s.ac != t.ac) return s.ac>t.ac;
if(s.ac == t.ac && s.time == t.time) return s.name<t.name;
if(s.ac == t.ac) return s.time<t.time;
return false;
};
int main(){
int wa,n,m,cost,k;//错误,题数,单位罚时,耗时
string str;
cin>>n>>m;
k=0;
while(cin>>stu[k].name){
for(int i=0;i<n;i++){
wa=0;cost=0;
cin>>str;
if(str[0]=='0' || str[0]=='-')
continue;
for(int j=0;j<str.length();j++){
if(str[j]=='('){
j++;
while(str[j] !=')'){
wa=wa*10+str[j]-'0';
j++;
}
break;
}
else cost=cost*10+str[j]-'0';
}
stu[k].ac++;
stu[k].time +=cost+wa*m;
}
k++;
}
sort(stu,stu+k,cmp);//对齐
for(int h=0;h<k;h++){
cout.flags(ios::left);
cout << setw(10) << stu[h].name << " ";
cout.flags(ios::right);
cout << setw(2) << stu[h].ac << " ";
cout << setw(4) << stu[h].time;
cout << endl;
}
return 0;
}
Explannation:
Obviously,we should definite a structure of students or you can say competitors.And then count the number of problems they solved,calculate time punishment.Here are the rules,for example,GuGuDong,actually he solved three problems,but the second problem he had made mistakes three times.Therefore,as the punishment,it takes him 3*20=60 minutes.In total,his scores:96+40+1+60=197;
you can use the regularity to solve all of details of this problem.