C语言中有并列情况的排序用什么语句?

例如:输入是99,95,89,90,99 输出为: 第一名 99 第一名 99 第三名 95 第四名 90 第五名 89 #include <iostream> using namespace std; int main() { int a[5]; int i,j,t; cout<<"输入5个成绩:"<<endl; for (i=0;i<5;i++) cin>>a[i]; cout<<endl; for (j=0;j<4;j++) for (i=0;i<4-j;i++) if (a[i]<a[i+1]) { t=a[i];a[i]=a[i+1];a[i+1]=t; } cout<<"排序:"<<endl; for (i=0;i<5;i++) cout<<"第"<<i+1<<"名"<<" "<<a[i]<<" "<<endl; cout<<endl; return 0; } 怎样修改啊?

/*author: phw *date: 10-09-22 *function: 将两个有序的单链表归并成一个有序的单链表 */ /*#include <stdio.h> #include <malloc.h> #define LEN sizeof(struct Node) #define N1 10 #define N2 10 typedef struct Node { int elem; struct Node *next; }; void Creat_Linklist(struct Node *p,int n) { static int i=0; struct Node *q=p; // q=p; while(i<=n) { q->elem=i; q->next=(struct Node *)malloc(LEN); q=q->next; i+=2; } q->next=NULL; q->elem=0; i=1; } /////////////////////////////////////////////////////////////////////////// //有序的归并两个有序的链表 void Merge_Linklist(struct Node *p1,struct Node *p2,struct Node *p3) { struct Node *q=p3; //q=p3; while (p1->next&&p2->next) { if (p1->elem<=p2->elem) { q->next=p1; q=p1; p1=p1->next; } else { q->next=p2; q=p2; p2=p2->next; } } q->next=p1?p1:p2; } /////////////////////////////////////////////////////////////////////////// void Print_Linklist(struct Node *p) { while (p->next) { printf("%d ",p->next->elem); p=p->next; } } void main() { struct Node *h1=NULL,*h2=NULL,*h3=NULL; h1=(struct Node *)malloc(LEN); h2=(struct Node *)malloc(LEN); h3=(struct Node *)malloc(LEN); Creat_Linklist(h1,N1); Creat_Linklist(h2,N2); Merge_Linklist(h1,h2,h3); Print_Linklist(h3); }*/ #include <iostream> using namespace std; int main() { int a[5]; int i,j,t; cout<<"输入5个成绩:"<<endl; for (i=0;i<5;i++) cin>>a[i]; cout<<endl; for (j=0;j<4;j++) for (i=0;i<4-j;i++) if (a[i]<a[i+1]) { t=a[i];a[i]=a[i+1];a[i+1]=t; } cout<<"排序:"<<endl; for (i=0;i<5;i++) { if(a[i]==a[i+1]) { cout<<"并列第"<<i+1<<"名"<<" "<<a[i]<<" "<<endl; i++; }else{ cout<<"第"<<i+1<<"名"<<" "<<a[i]<<" "<<endl; } } cout<<endl; return 0; } 这里仅仅给出仅仅是二个重复的,多的可以参考。 有问题相互讨论哦,嘿嘿
温馨提示:答案为网友推荐,仅供参考
相似回答