整理音乐 (链表归并)

整理音乐

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<string.h>
#include<stdlib.h>
struct nobe
{
    int data;
    char name[10];
    struct nobe *next;
}*p,*head,*q,*tail;
int main()
{
    int n,m;
    head=(struct nobe*)malloc(sizeof(struct nobe));
    head->next=NULL;

    scanf("%d",&n);
    int kkk=1;
    int cnt;
    while(n--)
    {
        scanf("%d",&m);
        while(m--)
        {
            p=(struct nobe *)malloc(sizeof(struct nobe));
            p->next=NULL;
            scanf("%s%d",p->name,&p->data);
            if(kkk==1)
            {
                kkk=0;
                head->next=p;
            }
            else
            {
                cnt = 1;
                int cntt=1;
                q=head;
                while(q->next)
                {
                    if(q->next->data>p->data)
                    {
                        q=q->next;
                    }

                    else if(q->next->data==p->data)
                    {
                        if(strcmp(q->next->name,p->name)<0)
                            {
                           q=q->next;
                            }

                        else
                        {
                            p->next=q->next;
                            q->next=p;
                            break;
                        }
                    }
                    else
                    {
                        p->next=q->next;
                        q->next=p;
                        break;
                    }
                }
                if(q->next==NULL)
                    q->next=p;
            }
        }
    }
    p=head->next;
    while(p)
    {
        printf("%s ",p->name);
        p=p->next;
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<algorithm>

using namespace std;

struct node
{
	int data;
	char s[10];
}p[100000];
int cmp(node p1,node p2)
{
	if(p1.data>p2.data)
		return 1;
	else if(p1.data==p2.data)
	{
		if(p1.s<p2.s)
			return 1;
	    else
			return 0;
	}
	return 0;
}
int main()
{
	int T;
	while(~scanf("%d",&T))
	{
		int num=0;
		while(T--)
		{
			int n;
			scanf("%d",&n);
			for(int i=0;i<n;i++)
			{
				cin>>p[num].s>>p[num].data;
				num++;
			}
		}
		sort(p,p+num,cmp);
		for(int i=0;i<num;i++)
		{
			if(i!=0)
				printf(" ");
			cout<<p[i].s;
		}
		cout<<endl;
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值