| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2685 人关注过本帖
标题:请各位大佬帮我解决一下这道题
只看楼主 加入收藏
asdfaad
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:25
专家分:0
注 册:2018-12-21
结帖率:57.14%
收藏
 问题点数:0 回复次数:1 
请各位大佬帮我解决一下这道题
出场顺序
(时间限制:1000ms 内存限制:65536KB)
统计
描述
元宵节晚会上,参加节目表演的同学需要抽签决定出场顺序,序号小的同学先出场,现在已知n(0<n<100)位同学的姓名和抽到的号码(无重复),请将同学们的姓名,按照出场次序输出。
注:假设班上无同名的学生。


输入
第一行为一个数字n,表示班上有n名同学的信息。   
接下来有n行,每行包括同学的姓名和出场号,以空格隔开。

输出
n行,每行表示一个按照出场号排好的同学姓名。

难度


输入示例
5
xinyu 4
haomiao 3
tiansen 6
jintao 2
zhangze 5

输出示例
jintao
haomiao
xinyu
zhangze
tiansen
搜索更多相关主题的帖子: 同学 姓名 输出 表示 示例 
2019-03-02 08:53
fulltimelink
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:7
帖 子:171
专家分:752
注 册:2020-4-1
收藏
得分:0 
程序代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
struct Student {
    char theName[100];
    int theNo;
};

int cmpFunc(const void *a, const void*b) {
    return (*(struct Student **)b)->theNo - (*(struct Student **)a)->theNo;
}



void sort_array(struct Student **a, int n)
{
    int i, j;
    struct Student *tmp;
    //排序, 选择法排序
    for (i = 0; i < n - 1; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (a[i]->theNo - a[j]->theNo > 0)
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
}


int main() {
    int theNum;
    scanf("%d", &theNum);
    assert(0 < theNum && theNum < 100);
    struct Student **ss = (struct Student**)malloc(theNum * sizeof(struct Student *));
    assert(NULL != ss);
    for (int i = 0; i < theNum; i++) {
        *(ss + i) = (struct Student*)malloc(sizeof(struct Student));
        scanf("%s %d", (*(ss+i))->theName, &((*(ss+i))->theNo));
    }
    //qsort(ss, theNum, sizeof(struct Student *), cmpFunc);
    sort_array(ss, theNum);
    for (int i = 0; i < theNum; i++) {
        printf("%s\n",(*(ss + i))->theName);
        free(*(ss + i));
    }
    free(ss);
    return 0;
}
2020-06-06 06:41
快速回复:请各位大佬帮我解决一下这道题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015108 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved