B- evaluation system

Topic Overview

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 Output

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 format described in the number of questions marks, see the table above.

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 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

Problem-solving ideas

1. Because of this problem requires multiple keyword ranking, thus defining a structure Stu comparison operation and overload.

2. Define Score character array [] student scores recorded for each question, the time points when the ac calculated separately and time penalties. ac Time: a first array element is determined, if it is '-' not '0', then it must be the subject of ac, and then traverse the string, the '(' before the numbers add up (if any) when penalty: if left parenthesis, brackets traverse an array of characters from the left to right parenthesis, add up the numbers in brackets.

3. sort Sort finally.

Code

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

//定义student结构体,并重写比较操作 
struct Stu{
 int a,b;//a为AC题数,b为时间 
 char name[10];
 bool operator< (const Stu &stu) const{
  if(a!=stu.a) return a>stu.a;
  if(b!=stu.b) return b<stu.b;
  return strcmp(name,stu.name)<0;//字典序升序 
 } 
}st[100005];

int n,m; //n为题数(1<=n<=12),m为单位罚时(10<=m<=20) 
int k=0; //k用于记录学生个数 
char score[1000];//存储学生每道题的得分情况 

int main()
{
 cin>>n>>m;
 while(~scanf("%10s",st[k].name))
 {
  st[k].a=0;
  st[k].b=0;
    for(int i=0;i<n;i++)
  {
   cin>>score;
   if(score[0]!='-'&&score[0]!='0')   
   {
    st[k].a++; //计算AC的题目个数 
    int label=0,num=0;
    for(int j=0;j<strlen(score);j++)
    {//此轮for循环计算ac时间 
     if(score[j]=='(')
     {
      label=j; //若有括号,label用于记录左括号的位置 
      break; 
     }
     num=num*10+score[j]-'0';//计算AC的时间 
    }
        st[k].b+=num; 
    num=0;
    if(label) 
    { 
     for(int j=label+1;j<strlen(score)-1;j++)
     {//此轮for循环计算罚时 
      num=num*10+score[j]-'0';
     }    
    }
    st[k].b+=num*m;
       }
  }
  k++;
  sort(st,st+k);  
 }
 for(int i=0;i<k;i++)
 {
  printf("%-10s %2d %4d\n",st[i].name,st[i].a,st[i].b);
 // cout<<setw(10)<<setfill(' ')<<st[i].name<<" "<<setw(2)<<setiosflags(ios::right)<<st[i].a<<" "<<setw(4)<<setiosflags(ios::right)<<st[i].b<<endl;
 }
 return 0;
} 

to sum up

1. With regard to format the output, just remember cout, setw, and how to forget printf% plus the width of it! ! Positive default right-aligned, left-aligned negative, remember! !
2. This question points ... silly comparison: the final result in the loop output! ! Simply check to see when the last set of examples and sample the same, did not pay attention to the output of the previous n-1 times change ... bald head does not know what wrong ... Fortunately, the students reminded me that will never do it again ...

Released five original articles · won praise 0 · Views 150

Guess you like

Origin blog.csdn.net/EllaSmith/article/details/104682609