1 /* 2 * Main.c 3 * 1004. 成績排名 4 * Created on: 2014年8月28日 5 * Author: Boomkeeper 6 ***********測試通過********* 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; //題目中的n 20 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 %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 %s\n", stuMax.name, stuMax.num); 48 printf("%s %s\n", stuMin.name, stuMin.num); 49 50 return 0; 51 }
題目鏈接:
http://pat.zju.edu.cn/contests/pat-b-practise/1004
參考:
http://www.cnblogs.com/shuanghong/archive/2013/04/16/3024998.html
1,n應該是動態的,現在你最大到100(非致命)
2,c語言裡面數組是從0開始的,循環中要從0開始(非致命)
“一提交部分正確”什麼意思?
程序在win-tc和Dev-c++下調試通過,這個程序是在你源程序的基礎上改寫而成:
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
main()
{
int s[5][5]={{1001,80,75,98,75},{1002,75,95,85,74},{1003,68,85,84,86},{1004,75,85,86,84},{1005,75,84,84,75}};/*定義二維數組,存放成績,是s[5][5]不是s[5][6],因為它是正數不是字符串最後沒有'\0',所以最後無需多加一位*/
int i,j,k,sum[5],sum1[5];
static char *a[5]={"tan","li","cheng","fang","zheng"};/*定義指針數組,存放姓名,即a[5]是包含5個指針元素的指針數組,5個指針中每個的值是該字符串的首地址*/
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]是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");
/* 冒泡排序 */
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......余下全文>>