64,674
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int n;
int *time1;
int *order;
int bubble()
{
for(int x=0;x<n;x++)
{
for(int y=n-1;y>=x;y--)
{
if(time1[y]<time1[x])
{
swap(time1[x],time1[y]);
swap(order[x],order[y]);
}
}
}
}
main()
{
double aver=0;
cin>>n;
time1=new int[n];
order=new int[n];
for(int i=0;i<n;i++)
{
cin>>time1[i];
order[i]=i+1;
}
bubble();
for(int i=0;i<n-1;i++)
{
cout<<order[i]<<" ";
aver+=time1[i]*(n-i-1);
}
cout<<order[n-1];
aver/=n;
cout<<endl<<aver<<endl;
/*
for(int i=0;i<n;i++)
{
cout<<time1[i]<<" ";
}
*/
}
int bubble()
{
for(int x=0;x<n-1;x++)
{
for(int y=1;y<n-x;y++)
{
if(time1[y]<time1[y-1])
{
swap(time1[y-1],time1[y]);
swap(order[y-1],order[y]);
}
}
}
}
void bubble()
{
for(int x=0;x<n;x++)
{
for(int y=n-1;y>x;y--)
{
if(time1[y]<time1[y-1])
{
swap(time1[y-1],time1[y]);
swap(order[y-1],order[y]);
}
}
}
}