整理音乐
2016-03-27 16:22
274 查看
整理音乐
Time Limit: 1000MS Memory limit: 65536K
题目描述
请用链表完成下面题目要求。xiaobai 很喜欢音乐,几年来一直在收集好听的专辑。他有个习惯,每次在听完一首音乐后会给这首音乐打分,而且会隔一段时间给打好分的音乐排一个名次。今天 xiaobai 打开自己的音乐文件夹,发现有很多不同时期打过分的排好序的子音乐文件夹,他想把这些音乐放到一块,组成一个分数有序的序列。由于音乐文件很多,而文件里音乐的数目也是不确定的,怎么帮帮 xiaobai 完成这件工作呢?
输入
输入数据第一行为一个整数n(n<1000),代表文件夹的数量。接下来是n个文件夹的信息,每个文件夹信息的第一行是一个数字m(m<=10000),代表这个文件夹里有m首歌,后面m行每行一个歌曲名、分数,之间用空格分开。歌曲名称不超过5个字符。输出
输出一行,为所有音乐组成的一个序列,音乐只输出名字。如果音乐分数相同则按照音乐名字典序进行排序。
示例输入
34aaa 60aab 50aac 40aad 302kkk 60kkd 593qow 70qwe 60qqw 20
示例输出
qow aaa kkk qwe kkd aab aac aad qqw
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int data; char s[30]; struct node *next; }; struct node *creat(int n) { struct node *head, *tail, *q; head = (struct node *)malloc(sizeof(struct node)); head->next = NULL; tail = head; int i; for(i = 0;i < n;i++){ q = (struct node *)malloc(sizeof(struct node)); scanf("%s %d", q->s, &q->data); q->next = NULL; tail->next = q; tail = q; } return head; } struct node *merge(struct node *head1,struct node *head2) { struct node *p1, *p2, *tail; p1 = head1->next; p2 = head2->next; tail = head1; while(p1 && p2){ if(p1->data >p2->data){ tail->next = p1; tail = p1; p1 = p1->next; }else if(p1->data <p2->data){ tail->next = p2; tail = p2; p2 = p2->next; }else { if(strcmp(p1->s,p2->s) <0){ tail->next = p1; tail = p1; p1 = p1->next; }else { tail->next = p1; tail = p2; p2 = p2->next; } } } if(p1){ tail->next = p1; }else { tail->next = p2; } return head1; } int main() { int n, m; int i; scanf("%d %d", &n, &m); struct node *head1, *head2, *p; head1 = creat(m); for(i = 2;i <= n;i++){ scanf("%d", &m); head2 = creat(m); head1 = merge(head1, head2); } p = head1->next; while(p != NULL){ if(p->next != NULL){ printf("%s ", p->s); }else { printf("%s", p->s); } p = p->next; } return 0; }
相关文章推荐
- mac下给vim添加行号
- HDU 1242 rescue (优先队列模板题)
- Java的接口
- 防止头文件重复包含的两种方法及区别
- nyoj 510 昂贵的聘礼
- ACM ProblemK
- iCamera App Kit 使用说明
- rodrigue 公式r-v v-r
- ACM第一次练习—1002C
- 一定要坚持
- BestCoder Round #77 (div.2) -so easy(组合)
- 分享一个 原生javaScript - 用面向对象写的下拉菜单 - DropdownMenu
- 63. Unique Paths II
- python查看类的定义
- 公元2016年3月27日。执行力。
- 函数指针与指针函数
- Struck: Structrued Output Tracking with Kernels 论文笔记
- struts2中的constant配置详解
- 数据库-T-SQL 语句-创建表,删除表,CRUD操作的添加数据,修改数据,删除数据
- mysql Table 'performance_schema.session_variables' doesn't exist