[Programming thinking and practice Week2 experiment B] burst zero (×) vigorously a miracle (√)

Meaning of the questions:

Thinking and real-time programming job evaluation systems used in the experiment, have timely access to performance ranking feature, that its function is how to achieve it?

We've written procedures and submitted after the evaluation system or return to AC, either to return various other error, no matter how wrong method, it will record your time submitting your mistakes, and when you eventually it experienced untold after the AC, it will display this problem in all the dates several times.

In the long course of years, the number of questions you pass though more and more, but by the time you have spent a total time of each question (from the start date until this time by title) will be recorded, as you ever struggle at the scene. In particular, for the topic you pass, you have concerning this question will be filed each time an error count when a certain unit time penalty, so that you make on a number of questions, which may lead many others, but in humans make the same number of questions, you may be too high because the penalty at a disadvantage on the rankings.

For example a test as a total of eight questions (A, B, C, D, E, F, G, H), each made questions are to have a number of markers in question number corresponding to a negative number indicates the title of the student had submitted the wrong number, but until now no AC, AC positive number indicates that the consumption of time, if a positive number to keep up with a pair of brackets, which has a positive number b, it means the student AC this question, It consumes a time a, b submitted at the same time had the wrong times. Examples can be seen the input and output sample section below.

Input:

When the input data comprises a plurality of rows, a first row are common title number n (1≤n≤12) and unit penalty m (10≤m≤20), each row of data after the description of a student information, first student user name (no more than a string of 10 characters) followed questions all n status score, which describes the number of questions in a format described in labeled, as was described above.

Simple 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 -9999996 -666 -10 086 0 0 -8
yjq 37 -2 (2) -1 13 0113 (2) 79 (1) -1
Zjm 0 0 57 (5) 0 0 99 (3) -7 0

Output:

According to the status of these students scoring output of a real-time ranking. Real-time ranking is obviously the question of how much the number of AC press row, more than the former, then how much time points row, small front before happened if both are equal, press the name of lexicographical row, smallest first . Each student per line, output the name (10 characters wide), the number of questions to make (2 characters wide, right-justified) and time points (four characters wide, right-justified). Name, title and the number of time points there is a space between each other. Data can ensure the required output format output.

Sample Output:

TT 5348
yjq 4342
GuGuDong 3197
HRZ 3256
Zjm 2316
OMRailgun 0 0

Ideas:

Players build a type of structure, in which the number of questions with the name of saving a char array, respectively hold two integer ac and ac current total time of the title, a two-dimensional array of type long long time and save the dates ac frequency . Write cmp function for comparing different players to arrive at the final ranking. After entering the format, using the sort () function to rank the output by format.

Code:

#include <iostream>
#include <stdio.h>
#include <string>
#include<string.h>
#include <vector>
#include<algorithm>
using namespace std;
struct peo{
	char name[15];
	int numofac,time;
	long long **a;
	int numofques;
	peo(char*thename,int n)
	{
		numofques=n;
		numofac=0;
		time=0;
		strcpy(name,thename);
		a=new long long*[n];
		for(int i=0;i<n;i++)
		{
			a[i]=new long long[2];
		}
	}
	peo(const peo&b)
	{
		strcpy(name,b.name);
		this->numofac=b.numofac;
		this->time=b.time;
		this->numofques=b.numofques;
		a=new long long*[numofques];
		for(int i=0;i<numofques;i++)
		{
			a[i]=new long long[2];
		}
		for(int i=0;i<numofques;i++)
		{
			for(int j=0;j<2;j++)
				a[i][j]=b.a[i][j];
		}
	}
};
bool cmp(peo&a,peo&b)
{
	if(a.numofac!=b.numofac)
	{
		return a.numofac>b.numofac;
	}
	else if(a.time!=b.time)
	{
		return a.time<b.time;
	}
	else
	{
		return strcmp(a.name,b.name)<0;
	}
}
int main(int argc, char** argv) {
	int n,m;
	scanf("%d %d",&n,&m);
	//getchar();
	vector<peo> a;
	char name[10];
	while(scanf("%s",name)!=EOF)
	{
		peo temp(name,n);
		string str;
		for(int i=0;i<n;i++)
		{
			cin>>str;
			if(str[str.size()-1]==')')
			{
				sscanf(str.c_str(),"%lld(%lld)",&temp.a[i][0],&temp.a[i][1]);
				temp.numofac++;
				temp.time+=(temp.a[i][0]+temp.a[i][1]*m);
			}
			else{
				sscanf(str.c_str(),"%lld",&temp.a[i][0]);
				if(temp.a[i][0]>0)
				{
					temp.numofac++;
					temp.time+=temp.a[i][0];
				}
			}
		}
		a.push_back(temp);
		//getchar();
	}
	sort(a.begin(),a.end(),cmp);
	//vector<peo>::iterator it=a.begin();
	//printf("%-10s %2lld %4lld",(*it).name,(*it).numofac,(*it).time);
	for(vector<peo>::iterator it=a.begin();it!=a.end();it++)
	{
		printf("%-10s %2lld %4lld\n",(*it).name,(*it).numofac,(*it).time);
	}
	return 0;
}
Published 25 original articles · won praise 8 · views 546

Guess you like

Origin blog.csdn.net/weixin_44034698/article/details/104635042