Experiment 2 B score ranking

topic

The real-time evaluation system used for programming thinking work and experiments has the characteristics of obtaining rankings in time. How does its function be realized?
After we have painstakingly finished the program that we couldn't bear to look directly at and submitted it, the evaluation system will either return AC or various other errors. No matter what the wrong method is, it will always give you a note to show you It was once pitted here, and after you have passed it through thousands of hours and finally AC it, it will calculate the general ledger with you, indicating that this question has been submitted several times in error. Although the number of questions you pass increases, the time you spend passing each question (from the beginning until the time when you pass the question) will be recorded as a trace of your struggle. . In particular, for the question you pass, every wrong submission you made on this question will be counted as a certain unit time penalty. In this way, you may be ahead of others in the number of questions you make, but Among those who make the same number of questions, you may be at a disadvantage in ranking because of the high penalty.
For example, there are a total of eight questions (A, B, C, D, E, F, G, H) in an exam. Each person ’s question has a quantity mark under the corresponding question number. A negative number indicates that the student is on the question There have been mistaken submissions but there is no AC until now. A positive number indicates the time spent by the AC. If the positive number a is followed by a pair of parentheses and there is a positive number b, it means that the student has taken this question. It took time a, and at the same time, b submitted it incorrectly. For examples, see the sample input and output sections below.
The input data contains multiple lines. The first line is the total number of questions n (1≤n≤12) and the unit penalty time m (10≤m≤20). Each subsequent line of data describes the information of a student, the first is the student ’s The username (a string of no more than 10 characters) is followed by the current status of all n questions. The description is in the format of the quantity mark in the problem description, see the table above.
According to the current status of these students' scores, a real-time ranking is output. The real-time ranking is obviously ranked first by the number of AC questions, more in front, then by time, and less in front. If it happens that the first two are equal, then it is sorted by name in lexicographic order, and the small first. . Each student occupies one line, and outputs the name (10 characters wide), the number of questions (2 characters wide, right aligned) and the time (4 characters wide, right aligned). There is a space between the name, the number of questions and the time. The data is guaranteed to be output in the required output format.

Ideas

Define a person's structure to store name, number of questions acNum, total time time, according to the input format, acNum is equal to the number of inputs whose first character is not '-' and '0', time is equal to the value of the time of the question + error * When the unit is penalized, it is finally sorted according to the cmp function sort and output.

to sum up

After this question, I found that my understanding of the string is very short

Code

#include<stdio.h>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct people 
{//保存学生的基本信息
	string name; 
	int acNum,time;
};
bool cmp(people&a,people&b){//为sort函数定义cmp
	if(a.acNum==b.acNum&&a.time==b.time)
		return  a.name<b.name;
	else
		if(a.acNum==b.acNum)
			return a.time<b.time;
		else
			return a.acNum>b.acNum;
}

string score;//输入的值
people p[10000];

int main()
{
	int n,m;
	cin>>n>>m;//n for 题数,m for 单位罚时 
	int num=0;
	while(cin>>p[num].name)
	{
		p[num].acNum=p[num].time=0;
		for(int i=0;i<n;i++)
		{
			cin>>score;
			if(score[0]=='0'||score[0]=='-')//未通过
			continue; 
			int time2=0,time1=0;
			p[num].acNum++;
			for(int i=0;i<score.length();i++){
				if(score[i]>='0'&&score[i]<='9')//记录过题的时间
					time2=time2*10+score[i]-48;
				if(score[i]=='('){
					for(int j=i+1;j<score.length()-1;j++){ 
						time1=time1*10+score[j]-48;//记录错误数
					}					
					break; 
				}
			}
			p[num].time+=time2+time1*m;//汇总总时间
		}
		num++; 
	 }

sort(p,p+num,cmp);
for(int i=0;i<num;i++)
{

	printf("%-10s %2d %4d\n",p[i].name.c_str(),p[i].acNum,p[i].time);
}
 return 0;
}

Published 20 original articles · praised 3 · visits 460

Guess you like

Origin blog.csdn.net/qq_44893580/article/details/104672251