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