Jiudu OnlineJudge 1014: Ranking_PHP Tutorial

WBOY
Release: 2016-07-13 17:19:15
Original
899 people have browsed it

Title description:                  

Although there is a real-time Ranklist for today’s computer-based exam, the ranking above is only based on the number of questions completed, and does not take into account the score of each question, so it is not the final ranking. Given the admission score, please write a program to find the candidates who finally passed the score and print their scores in descending order.
Input:                                                  
The test input contains information from several exams. The first line of each exam information gives the number of candidates N ( 0 < N < 1000 ), the number of test questions M ( 0 < M < = 10 ), and the score line (positive integer) G; the second line sorting gives Positive integer scores from questions 1 to The question number of the question (the question number ranges from 1 to M).
When the number of candidates read in is 0, the input ends and the exam will not be processed.
Output:                                                                      
For each exam, first output the number n of candidates who are not lower than the score line in the first line, and then output the test number and score of the online candidates from high to low in the n lines, separated by 1 space. If there are multiple candidates with the same score, the results will be output in ascending order of their exam numbers.
Sample input:                                                                      
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0
Sample output:                                                                    
3
CS003 60
CS001 37
CS004 37
0
1
CS000000000000000002 20
#include <iostream>  
#include <string>  
#include <vector>  
#include <algorithm>  
#include <cstring>  
  
using namespace std;  
  
  
typedef struct  persons  
{  
    string id;  
    int total;  
    int grade;  
}persons;  
  
bool  compare(persons a,persons b)  
{  
    if (a.grade!=b.grade)  
    return a.grade>b.grade;  
    else  
    return a.id < b.id;  
}  
  
  
int main()  
{  
    int N,M,G;  
  
    vector<persons>   vec;  
      
    int grade[11];  
  
      
  
    while(cin>>N,N!=0)  
    {  
        memset(grade,0,sizeof(grade));  
        vec.clear();  
        int ans=0;  
        cin>>M>>G;  
          
        for (int i=1;i<=M;i++)  
            cin>>grade[i];  
        for (int i=0;i<N;i++)  
        {  
            persons  p;  
            cin>>p.id>>p.total;  
            p.grade = 0;  
            for (int j=1;j<=p.total;j++)  
            {  
                int t;  
                cin>>t;  
                p.grade += grade[t];  
  
            }  
  
            if (p.grade >= G) ++ans;  
  
            vec.push_back(p);  
        }  
     sort(vec.begin(),vec.end(),compare);  
     cout<<ans<<endl;  
     for (int i=0;i<ans;++i)  
     {  
         cout<<vec[i].id<<" "<<vec[i].grade<<endl;  
  
     }  
  
  
  
  
    }  
  
  
  
  
    //system("pause");  
    return 0;  
}  
Copy after login

http://www.bkjia.com/PHPjc/532695.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532695.htmlTechArticleQuestion description: Although today’s computer-based exam has a real-time Ranklist, the ranking above is only based on the number of completed questions. The ranking does not take into account the score of each question, so it is not the final ranking. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!