整理音乐 (sdut oj)
整理音乐
Time Limit: 1000MS Memory Limit: 65536KBxiaobai
输出一行,为所有音乐组成的一个序列,音乐只输出名字。
如果音乐分数相同则按照音乐名字典序进行排序。
#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;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
