不过我自己又找出了好多问题改了改,现在还有一个问题没有解决,就是如何找到毛小杰的成绩#include <stdio.h>
#include <string.h>
typedef struct student
{
char name[105];
int grade;
} stu;
typedef struct students
{
char name1[105];
} stud;
typedef struct score
{
char name2[105];
int score;
} scr;
int n,m,i,j,a,b=1,sum1,sum2;
/*stud arr1[10005];
stu arr2[10005];
scr arr3[10005];*/
int main(void)
{
scanf("%d", &n);
stud arr1[n];
for(i=0;i<n;i++)
{
scanf(" %s", arr1[i].name1);
}
scanf("%d", &m);
a=n*m;
stu arr2[a];
scr arr3[n];
for(i=0;i<a;i++)
{
scanf("%d %s",&arr2[i].grade,arr2[i].name);
}
if (m>1)
{
for(i=0;i<n;i++)
{
for(j=n;j<a;j++)
{
if(strcmp(arr2[i].name, arr2[j].name) == 0)
{
sum1 = arr2[i].grade + arr2[j].grade;
arr2[i].grade = sum1;
arr3[i].score = arr2[i].grade;
strcpy(arr3[i].name2,arr2[i].name);
}
}
}
}
else
{
for(i=0;i<n;i++)
{
arr3[i].score = arr2[i].grade;
strcpy(arr3[i].name2,arr2[i].name);
}
}
for (i=0;i<n; i++) {
if(strcmp(arr1[0].name1,arr3[i].name2) == 0);
{
sum2 = arr3[i].score;
break;
}
}
for(i=0;i<n;i++)
{
if (arr3[i].score>sum2)
b=b+1;
}
for(i=0;i<n;i++)
{
printf("%d %s\n",arr3[i].score,arr3[i].name2);
}
for(i=0;i<n;i++)
{
printf("%s\n",arr1[i].name1);
}
printf("%d %d\n",sum1,sum2);
printf("%d\n",b);
return 0;
}
|