#include<iostream>
#include<string>
using namespace std;
const int num=8;
int main()
{
int i,j,t;
string temp;
string name[num]= {"zhao","qian","sun","li","zhou","wu","zheng","wang"};
double score[num]= {79,84,65,89,60,92,78,56};
for(i=0; i<num; ++i)
{
for(j=0; j<num-1-i; ++j)
{
if(score[j]>score[j+1])
{
t=score[j];
score[j]=score[j+1];
score[j+1]=t;
temp=name[j];
name[j]=name[j+1];
name[j+1]=temp;
}
}
}
cout<<"按成绩从小到大排";
for(i=0; i<8; ++i)
{
cout<<name[i]<<" "<<score[i]<<endl;
}
for(i=0; i<num; ++i)
{
for(j=0; j<num-1-i; ++j)
if(name[j]>name[j+1])
{
t=score[j];
score[j]=score[j+1];
score[j+1]=t;
temp=name[j];
name[j]=name[j+1];
name[j+1]=temp;
}
}
cout<<"按姓名排序";
for(i=0; i<8; ++i)
{
cout<<name[i]<<" "<<score[i]<<endl;
}
return 0;
}
排序
最新推荐文章于 2024-06-06 09:35:49 发布