Title 1014: Ranking (structure sort)

Source: Internet
Author: User
Tags array sort

Source of the problem

  http://ac.jobdu.com/problem.php?pid=1014

Problem Description

The number of candidates to enter N (0 < N < 1000), the number of questions m (0 < M < = 10), the bar (positive integer) G, followed by the 1th question to the question of the positive integer score, followed by each candidate's ticket number (the length of the string not exceeding 20), the total number of topics m, to And the question number of the M-question (question number from 1 to m).

Problem Analysis

directly to the processing, calculate the total score of each student, more than the bar is added to the structure array, the last array sort, the output can be.

Note The custom CMP comparison function is written as: Returns True if the former is in front.

Reference Code
////Created by Alvinzh on 2017/5/24.//Copyright (c) alvinzh. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespaceStd;typedefstructstu{Charid[ -]; intMark;}; Stu s[1005];BOOLcmpConstStu &a,ConstStu &b) {    if(a.mark!=B.mark)returnA.mark>B.mark; Else        returnstrcmp (A.id,b.id) <0;}intMain () {intn,m,g; intgrade[ One]; intCount;  while(~SCANF ("%d", &n) &&n!=0) {Count=0; scanf ("%d%d",&m,&G);  for(intI=1; i<=m;i++) scanf ("%d",&Grade[i]); Charsid[ -]; intm; intQid; intSUMG;  for(intI=1; i<=n;i++) {SUMG=0; scanf ("%s%d",&sid,&m);  for(intj=1; j<=m;j++) {scanf ("%d",&Qid); SUMG+=Grade[qid]; }            if(sumg>=G) {strcpy (S[COUNT].ID,SID); S[count]. Mark=SUMG; Count++; }} sort (S,s+count,cmp); printf ("%d\n", Count);  for(intI=0; i<count;i++) printf ("%s%d\n", S[i].id,s[i].    Mark); }}

Alvinzh

Source: http://www.cnblogs.com/AlvinZH/

I Github:https://github.com/pacsiy/jobdu

The copyright belongs to the author Alvinzh and blog Park all, welcome reprint and Commercial, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Title 1014: Ranking (structure sort)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.