整理音乐 (sdut oj)

整理音乐

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description 请用链表完成下面题目要求。
xiaobai 
很喜欢音乐,几年来一直在收集好听的专辑。他有个习惯,每次在听完一首音乐后会给这首音乐打分,而且会隔一段时间给打好分的音乐排一个名次。今天  xiaobai  打开自己的音乐文件夹,发现有很多不同时期打过分的排好序的子音乐文件夹,他想把这些音乐放到一块,组成一个分数有序的序列。由于音乐文件很多,而文件里音乐的数目也是不确定的,怎么帮帮  xiaobai  完成这件工作呢?
Input 输入数据第一行为一个整数nn<1000),代表文件夹的数量。接下来是n个文件夹的信息,每个文件夹信息的第一行是一个数字m(m<=10000),代表这个文件夹里有m首歌,后面m行每行一个歌曲名、分数,之间用空格分开。歌曲名称不超过5个字符。
Output

输出一行,为所有音乐组成的一个序列,音乐只输出名字。

如果音乐分数相同则按照音乐名字典序进行排序。


Example Input 3 4 aaa 60 aab 50 aac 40 aad 30 2 kkk 60 kkd 59 3 qow 70 qwe 60 qqw 20 Example Output qow aaa kkk qwe kkd aab aac aad qqw Hint
Author




参考代码

#include
#include
#includestruct music
{char name[10];int fen;struct music *next;
};struct music *sc(int t,struct music *p)
{while( p->next != NULL ){if( t == p->next->fen ){return p;}p = p->next;}if( p->next == NULL )return p;
};int main()
{int m,n;int i,j;struct music *head,*head1,*p,*tail,*q,*tail1,*t;head = (struct music *)malloc(sizeof(struct music));head->next = NULL;scanf("%d",&n);while(n--){head1 = (struct music *)malloc(sizeof(struct music));head1->next = NULL;tail = head1;scanf("%d",&m);while(m--){p = (struct music *)malloc(sizeof(struct music));scanf("%s%d",&p->name,&p->fen);p->next = tail->next;tail->next = p;tail = p;}p = head->next;q = head1->next;tail = head;head->next = NULL;head1->next = NULL;free(head1);while( p != NULL && q != NULL ){if( p->fen > q->fen ){tail->next = p;p = p->next;}else if( p->fen == q->fen ){if( strcmp(p->name,q->name) > 0 ){tail->next = q;q = q->next;}else{tail->next = p;p = p->next;}}else{tail->next = q;q = q->next;}tail = tail->next;}if( p != NULL ){tail->next = p;}if( q != NULL ){tail->next = q;}}p = head->next;i = 0;while( p != NULL ){if( i == 0 ){i = 1;printf("%s",p->name);}else{printf(" %s",p->name);}p = p->next;}printf("\n");return 0;
}



本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部