将一组数据从大到小排列后输出,要求显示每个元素及它们在原数组(用C++编程,有什么更好的方法?谢谢)

2025-03-06 11:46:13
推荐回答(2个)
回答1:

#include
using namespace std;
void main()
{
cout<<"input array with 6 elements:"< int a[6],b[6];
int i=0;
while(i<6)
{
cin>>a[i];
b[i]=i;
i++;
}
for(i=0;i<6;i++)
for(int j=i+1;j<6;j++)
{
if(a[i] {
int temp=a[i];
a[i]=a[j];
a[j]=temp;
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
cout<<"排序后数组从大到小为:"< for(i=0;i<6;i++)
cout< cout< cout<<"对应下标为:" < for(i=0;i<6;i++)
cout< cout<}

回答2:

map加数组...