Home > Back-end >  PTA 1004 scores ranking (20 point (s)), c (GCC)
PTA 1004 scores ranking (20 point (s)), c (GCC)

Time:10-05

Returns
1004 scores ranking (20 point (s))
Read in n (& gt; 0) student name, student id, achievements, respectively, the highest output performance and lowest student name and student id,

Input format:
Each test input contains one test case, the format for

Line 1: the positive integer n
Line 2: a student's name and student id 1 score
Line 3: the second student name and student id scores
. . .
N + 1: n a student's name and student id result



Including name and student number are a string of not more than 10 characters, performance for an integer between 0 and 100, this guarantee in a set of test cases that no two student's result is the same,

The output format:
For each test case output line 2, line 1 is the top student name and student number, line 2 will be the lowest grade student's name and student id, one space between strings,

Input the sample:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95



The output sample:
Mike CS991301
Joe Math990112


 # include 

Struct student {
Char name [10].
Char code [10].
Int score;
};

Int main (void)
{
Int student_num;
The scanf (" % d ", & amp; Student_num);
Struct student students [student_num];

int i;
Struct student first_student={" ", "", 1};
Struct student last_student;
for (i=0; i{
The scanf (" % d % s % s ", students [I]. Name, students [I] code, & amp; Students [I] score);
If (students [I] score & gt; First_student. Score)
First_student=students [I];
If (I==0) last_student=first_student;
Else if (students [I] score & lt; Last_student. Score)
Last_student=students [I];
The else
;
}

Printf (" % s % s \ n ", first_student. Name, first_student. Code).
Printf (" % s % s ", last_student. Name, last_student. Code).

return 0;
}


The Submit Time Status Score Problem Compiler Run Time User
3/13/2020, 11:37:30
Partially Accepted
2 1004 C (GCC) 4 ms lu_xianche
Case Result the Run Time Memory
0
Wrong Answer
2 ms 256 KB
1
Accepted
4 ms 256 KB
2
Wrong Answer
4 ms 384 KB

CodePudding user response:

Int student_num;
The scanf (" % d ", & amp; Student_num);
Struct student students [student_num];
C language does not support this definition, an array must be given a constant value

CodePudding user response:

 # include 
#include

Struct student {
//char name [10].
//char code [10];
Char name [32].
Char code [32].
Int score;
};

Int main (void)
{
Int student_num;
The scanf (" % d ", & amp; Student_num);
Struct student * students=(struct student *) malloc (sizeof (struct student) * student_num);
if (! Students)
exit(0);

int i;
Struct student first_student={" ", "", 1};
Struct student last_student;
for (i=0; i{
The scanf (" % d % s % s ", students [I]. Name, students [I] code, & amp; Students [I] score);
If (students [I] score & gt; First_student. Score)
First_student=students [I];
If (I==0)
Last_student=first_student;
Else if (students [I] score & lt; Last_student. Score)
Last_student=students [I];
//else
//;
}

Printf (" % s % s \ n ", first_student. Name, first_student. Code).
Printf (" % s % s \ n ", last_student. Name, last_student. Code).

return 0;
}


For your reference ~

C language does not support variable-length arrays, in addition, the name, code for the test cases, already crossed, so suggest to increase the length of the array (name, code)

CodePudding user response:

reference 1st floor CHXCHXKKK response:
int student_num;
The scanf (" % d ", & amp; Student_num);
Struct student students [student_num];
C language does not support this definition, an array must be given a constant value
variable-length arrays, can support
  • Related