1004. Score ranking, 1004 score ranking
1/* 2 * Main. c 3*1004. ranking 4 * Created on: August 28, 2014 5 * Author: boomkeeper 6 ************ passed the test *********** 7 */8 9 # include <stdio. h> 10 11 struct student {12 char name [11]; 13 char num [11]; 14 int score; 15}; 16 17 int main (void) {18 19 int n; // n20 int I, j; 21 struct student stuMax, stuMin, temp; 22 stuMax. score =-1; 23 stuMin. score = 101; 24 25 scanf ("% d", & n); 26 getchar (); 27 28 for (I = 0; I <n; I ++) {29 scanf ("% s % I", temp. name, temp. num, & temp. score); 30 getchar (); 31 32 if (stuMax. score <temp. score) {33 for (j = 0; j <11; j ++) {34 stuMax. name [j] = temp. name [j]; 35 stuMax. num [j] = temp. num [j]; 36} 37 stuMax. score = temp. score; 38} 39 if (stuMin. score> temp. score) {40 for (j = 0; j <11; j ++) {41 stuMin. name [j] = temp. name [j]; 42 stuMin. num [j] = temp. num [j]; 43} 44 stuMin. score = temp. score; 45} 46} 47 printf ("% s \ n", stuMax. name, stuMax. num); 48 printf ("% s \ n", stuMin. name, stuMin. num); 49 50 return 0; 51}
Question link:
Http://pat.zju.edu.cn/contests/pat-b-practise/1004
Refer:
Http://www.cnblogs.com/shuanghong/archive/2013/04/16/3024998.html
PAT 1004 score ranking helps you look at the code. I don't know where the error is. I submitted it partially correctly.
1, n should be dynamic. Now you have a maximum of 100 (non-fatal)
2. in C language, the array starts from 0 and the loop starts from 0 (non-fatal)
What does "one submission is partially correct" mean?
Store and sort scores using a C # Two-dimensional array
The program is successfully debugged under win-tc and Dev-c ++. This program is rewritten based on your source program:
# Include "stdio. h"
# Include "stdlib. h"
# Include "conio. h"
Main ()
{
Int s [5] [5] = {, 80, 75}, {, 75, 85, 74}, {, 68, 86, 86}, {, 86, 84 },{, 75, 75};/* defines a two-dimensional array and stores the score. The value is s [5] [5], not s [5] [6]. because it is a positive number and does not end with '\ 0', you do not need to add one more character */
Int I, j, k, sum [5], sum1 [5];
Static char * a [5] = {"tan", "li", "cheng", "fang", "zheng"};/* defines the pointer array and stores the name, that is, a [5] is a pointer array containing five pointer elements. Each value of the Five Pointers is the first address of the string */
Clrscr ();
Printf ("before: \ n ");
Printf ("--------------------------------------------------------------- \ n ");
Printf ("Name \ tAcad \ tMath \ tEnglish \ tVC \ tASP \ n ");
For (I = 0; I <5; I ++)
{
Sum [I] = 0;
For (j = 1; j <5; j ++)
Sum [I] = sum [I] + s [I] [j];
Sum1 [I] = sum [I];/* sum1 [5] is a backup of sum [5 */
Printf ("% s \ t", a [I]);
For (j = 0; j <5; j ++)
Printf ("% d \ t", s [I] [j]);
Printf ("% d", sum [I]);
Printf ("\ n ");
}
Printf ("---------------------------------------------------------------- \ n ");
Printf ("\ n ");
Printf ("\ n ");
/* Bubble sort */
For (I = 0; I <4; I ++)
For (j = 0; j <4-i; j ++)
If (sum1 [j] <sum1 [j + 1])
{
K = sum1 [j];
Sum1 [j] = sum1 [j + 1];
Sum1 [j + 1] = k;
}
Printf ("after: \ n ");
Printf ("---------------------------------------------------------------- \ n ");
Printf ("Name Acad Math Engli ...... remaining full text>