/* Note:Your choice is C IDE */
//每次的输入都有更新
#include "stdio.h"
#define N 45
/*函数声明*/
int inputSS(char names[][20],int score[],int num);
void printSS(char names[][20],int score[],int num);
void getMAX(char names[][20],int score[],int num);
/*主函数 */
main()
{
char names[N][20];
int score[N];
int num=0;
int choose;
printf("What do you what to do:INPUT(1),OUPUT(2),MAX(3),EXIT(0):");
scanf("%d",&choose);
do{
switch(choose){
case 1:
num=inputSS(names,score,num);
break;
case 2:
printSS(names,score,num);
break;
case 3:
getMAX(names,score,num);
break;
case 0:
exit(0);
}
printf("What do you what to do:INPUT(1),OUPUT(2),MAX(3),EXIT(0):");
scanf("%d",&choose);
}while(choose!=0);
}
/*函数定义*/
int inputSS(char names[][20],int score[],int num){
int n,i;
printf("\nThis time,how many students do you want to input :");
scanf("%d",&n);
if((n+num)>N||n<1){
printf("not valid sum\n");
return num;//改了
}
printf("now input as (name score): \n");
for(i=0;i<n;i++){
printf("%d.",i);
scanf("%s%d",&names[i],&score[i]);//修改了的,去了num
}
printf("this time ,input is over\n");
return n;//修改了的,去了num
}
void printSS(char names[][20],int score[],int num){
int i;
if(num==0){
printf("no students now\n");
return ;
}
printf("\n now ,the students scores as follows\n");
for(i=0;i<num;i++)
printf("%2d. name:%10s score:%3d\n",i,names[i],score[i]);
}
void getMAX(char names[][20],int score[],int num){
int i,max_index,max_score;
if(num==0){
printf("no students now\n");
return;
}
max_index=0;
max_score=score[0];
for(i=1;i<num;i++)
if(score[i]>max_score){
max_score=score[i];
max_index=i;
}
printf("The top score is %d bt %s \n",score[max_index],names[max_index]);
}