Hangzhou Electric acm1236--Rankings

Source: Internet
Author: User

This problem, more troublesome, can be said to be a simple application of structural body.

The amount of data input is relatively large, with scanf better, and a little more difficult is the same as the score, to the candidate number in ascending order to output.

I use a structure to save each candidate's test number and total scores, and then sort, calculate a few qualified, and then output.

The following is an AC code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace                    Std;class Data{public:char str[25];                         Test number int sum; Total score};d ATA student[1005];int cmp (const data& A, const data& B)//Sort from large to small {if (a.sum! = b.sum)//min  Number not the same as return a.sum > B.sum;else//Fractions, more trouble {int x = 0, y = 0;int len1 = strlen (A.STR); int Len2 = strlen (b.str); int i = 0, j = 0;while ((a.str[i] >= ' A ' && a.str[i] <= ' Z ') | |  (A.str[i] >= ' A ' && a.str[i] <= ' z ')) Ignore the preceding letter i++;while (a.str[i]! = ' + ')//Count a the number following the test number {x + = x * + (A.str[i]-' 0 '); i++;} while ((B.str[j] >= ' A ' && b.str[j] <= ' Z ') | |   (B.str[j] >= ' A ' && b.str[j] <= ' z ')) Ignore the preceding letter j++;while (b.str[j]! = ' + ')//Count B after the number {y + = y * + (B.str[j]-' 0 '); j + +;}              return x < y; From small to large row}}int main () {//freopen ("Data.txt", "R", stdin); int N, M, G;int sroce[12], I, J, K;while (scanf ("%d", &n)! = EOF && N! = 0)//input {scanf ("%d%d", &m, &g); for (i = 1; I <= M; i++)//score scanf for each question ("%d", &sroce[i]); for (i = 0; i < N; i++) {scanf ("%s%d", Student[i].s  TR, &j);     Enter the number and do a few questions student[i].sum = 0;while (j--) {scanf ("%d", &k); Student[i].sum + = Sroce[k];        Add up the scores}}sort (student, student + N, CMP); Sort int count = 0;for (i = 0; i < N; i++)//qualifying several {if (student[i].sum >= G) count++;elsebreak;}                  printf ("%d\n", count); Output for (i = 0; i < count; i++) printf ("%s%d\n", Student[i].str, student[i].sum);} return 0;}


Hangzhou Electric acm1236--Rankings

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.