legend


私信TA

用户名:dotcpp0599065

访问量:14988

签 名:

fish or cut baits

等  级
排  名 203
经  验 6470
参赛次数 0
文章发表 75
年  龄 0
在职情况 学生
学  校 黑龙江大学
专  业

  自我简介:

you can you up,no can don't bb

解题思路:排序就是简单的冒泡排序,重点核心内容是要学会使用结构体类型,这样以后写题就会变的方便

注意事项:这里注意的是这个ID号是字符类型,因为可能包含字母,所以要声明char类型,

参考代码:




#include<stdio.h>

int main()

{

    typedef struct people

    {

      char peopleID[100];

      int peopleyear;

    }PEOPLE;

    int n;

    int i;

    scanf("%d",&n);

    PEOPLE str[100];

    for(i=0;i<n;i++)

    {

        scanf("%s%d",str[i].peopleID,&str[i].peopleyear);

    }

    int j;

    PEOPLE temp;

    for(i=0;i<n;i++)

    {

        for(j=1;j<n;j++)

        {

            if((str[j].peopleyear>str[j-1].peopleyear)&&str[j].peopleyear>=60)

            {

                 temp=str[j];

                str[j]=str[j-1];

                str[j-1]= temp;

            }

        }

    }

             for(i=0;i<n;i++)

             {


                 printf("%s\n",str[i].peopleID);

             }


    return 0;

}


 

0.0分

2 人评分

  评论区

  • «
  • »