Programming Design Thought and Practice Week2 Experimentation: B-Explode Zero (*) Make a Great Miracle ()

Keywords: less

B - Blast zero (*) and work miracles hard ()

Title Description

The real-time evaluation system used in the thought job and experiment of program design is characterized by timely ranking of results. How is its function implemented?
After we have worked so hard to look straight into the program and submitted it, the system either returns AC or other errors. Whatever the wrong method, it will always write a note to you indicating that you have been pitted here. After you have worked so hard to get it AC, it will calculate a general ledger with you indicating that the problem has been submitted incorrectly several times.
Over the years, you've passed more and more questions, but the time you spend on each question (from the very beginning to the time you passed) is recorded as a sign of your struggle.In particular, each incorrect submission you made about the topic you passed will be counted as a unit time penalty. As a result, you may be ahead of others in the number of questions you have made, but among those who have made the same number of questions, you may be at a disadvantage in ranking because of the high penalty time.
For example, in an exam, there are eight questions (A,B,C,D,E,F,G,H). Each person's questions are marked by a number under the corresponding title. Negative numbers indicate the number of incorrect submissions that the student has made on the question but has not yet had AC. Positive numbers indicate the time taken by AC. If positive numbers a follow a pair of parentheses, there is a positive number b in them.It means that the student ACed this question, which took a long time and submitted it b times incorrectly.The example can be seen in the sample input and output section below.

Input

The input data contains multiple rows, the first row is the common number of questions n (1 < n < 12) and the unit penalty m (10 < m < 20). After that, each row of data describes a student's information. First, the student's user name (no more than 10 characters of string) is followed by the score status of all n questions. The description is in the format of quantity markers in question description, as shown in the table above.

Output

Output a real-time ranking based on the students'score status.Real-time ranking apparently starts with the number of AC questions, more in the first place, and then in the number of time points, less in the first place. If the first two items happen to be equal, they are sorted by the dictionary of names, the smaller in the first place.Each student takes one line, 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.

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

Sample Output

TT          5  348
yjq         4  342
GuGuDong    3  197
hrz         3  256
Zjm         2  316
OMRailgun   0    0

thinking

Create a student structure with name, number of questions ac, and penalty time.

struct Stu
  {//Student Information Architecture
     string name;
     int ac;//Number of questions 
     int time;//time penalty
  };

Title means multi-keyword sorting, where the structure sorting is overridden:

bool cmp(Stu p1,Stu p2){//Multiple keywords; 
   	if(p1.ac == p2.ac && p1.time==p2.time)
	  return p1.name < p2.name; 
    else {
	  if(p1.ac == p2.ac) return p1.time < p2.time;
      else return p1.ac > p2.ac;
    }
  }

Create an array of student structures. When data is input, one student completes index++ and begins recording the information of the next student.

Complete the space after the name when typing

int emp;
emp=10-theName.length();//Number of spaces in name;
for(int i=0; i<emp; i++) 
theName.append(" ");//Complete the spaces;

For the processing of fractions, first determine the plus and minus sign, if there is a negative sign, do not process, just pass'('
Split characters into time penalties and number of error submissions and process them separately.

sort all entries and output as required.

Code

#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

struct Stu
  {//Student Information Architecture
     string name;
     int ac;//Number of questions 
     int time;//time penalty
  };
const int maxn=1e3+5; 

bool cmp(Stu p1,Stu p2)
  {//Multiple keywords; 
   	if(p1.ac == p2.ac && p1.time==p2.time)
	  return p1.name < p2.name; 
    else 
	{
	  if(p1.ac == p2.ac) return p1.time < p2.time;
      else return p1.ac > p2.ac;
    }
  }

int main()
{
  Stu stu[maxn];	
  int n,m;
  int index=0;
  string theName; 
  cin>>n>>m;
  getchar();//Empty the buffer;
  
  while(cin>>theName)
  { int emp;
	emp=10-theName.length();//Number of spaces in name;
	for(int i=0; i<emp; i++) theName.append(" ");//Complete the spaces;
	stu[index].name=theName;
	stu[index].ac=0;
	stu[index].time=0;//Pretreatment;
	
	int qnum=n;//Number of questions; 
	for(int i=0;i<qnum;i++)
	{
		string score;//Score; 
		int time=0,penelty=0;
		cin>>score;
		if(score.find('-') != -1 || score.compare("0") == 0)
            continue;//Invalid score;
		//Effective score;
		stu[index].ac++; 
		for(int i=0; i<score.length(); i++)
	    {
	    	if(score[i] >= '0' && score[i] <= '9')
	    	    time=time*10+score[i]-48;//ASCAL code 0 is 48; 
	    	if(score[i] == '(')//Traverse to the time of penalty; 
			{
			     for(int k=i+1; k<score.length()-1; k++)
				     penelty=penelty*10+score[k]-48;	
			     break;//End of processing; 
  			}
		}
	    stu[index].time += time +penelty*m;  
	}   
  	index++;//Next student; 
   } 

  sort(stu,stu+index,cmp);

  for(int i=0; i<index; i++)
  {
    cout<<stu[i].name<<' ';
    
	if(stu[i].ac < 10)cout<<' ';
	cout<<stu[i].ac<<' ';
	
	if(stu[i].time<10)cout<<"   ";
	else if(stu[i].time<100)cout<<"  ";
	else if(stu[i].time<1000)cout<<" ";
	cout<<stu[i].time<<endl;	
  }
  return 0;	
}
Three original articles were published, 0 won and 13 visited
Private letter follow

Posted by gkelley091565 on Wed, 04 Mar 2020 19:00:16 -0800