结构体3

作者: 时间:2020-07-09 点击数:

void count(stu st[],int n,char tt[][20])  {
     int i,j;
  for(i=0;i<50;i++)
      for(j=0;j<3;j++)
    if (strcmp(tt[i],st[j].name)==0) st[j].cnt++;
 }
stu findking(stu tt[],int n)   {
     int i;
  stu st;
  st=tt[0];
  for(i=1;i<3;i++)
  if (tt[i].cnt>st.cnt) st=tt[i];
  return st;
  }
void sort(stu tt[],int n)
   {
      int i,j;
   stu temp;
   for(i=0;i<n-1;i++)
   for(j=0;j<n-1-i;j++)
   if (tt[j].cnt<tt[j+1].cnt)
      {temp=tt[j];tt[j]=tt[j+1];tt[j+1]=temp;} 
    }

int main(){
char xp[50][20]={"库里","哈登","阿德托昆博","阿德托昆博","库里","库里","阿德托昆博","库里","阿德托昆博","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","库里","阿德托昆博","阿德托昆博","哈登","阿德托昆博","阿德托昆博","库里","库里","哈登","库里","哈登","库里","库里","库里","库里","库里","哈登","哈登","哈登","哈登","库里","库里","哈登","哈登","哈登","库里","库里","库里","库里"};
stu hxr[3]={"哈登",0,"库里",0,"阿德托昆博",0};
stu pw;
int i;
count(hxr,3,xp);
for(i=0;i<3;i++)
 printf("%s:%d*",hxr[i].name,hxr[i].cnt);
printf("\n");
pw=findking(hxr,3);
printf("%s:%d\n",pw.name,pw.cnt);
sort(hxr,3);
for(i=0;i<2;i++)
 printf("%s:%d*",hxr[i].name,hxr[i].cnt);
printf("%s:%d",hxr[i].name,hxr[i].cnt);
printf("\n");
return 0;}

上一页 [1] [2] [3] [4] [5] 下一页

Copyright© 2020 Anyang Institute of Technology.All rights reserved.

学院地址:河南省安阳市黄河大道西段