想排序后进行操作,然后进行原序输出??;
可以记录一个顺序,之后对顺序排序,但也可如下;
1 // cout << sort; 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<iostream> 6 #include<algorithm> 7 #include<queue> 8 #include<cmath> 9 using namespace std; 10 struct e 11 { 12 int num; 13 int po; 14 }a[10000]; 15 int b[10000]; 16 bool cmp(e x,e y) 17 { 18 return x.num<y.num; 19 } 20 int main() 21 { 22 freopen("1.in","r",stdin); 23 freopen("1.out","w",stdout); 24 int n; 25 scanf("%d",&n); 26 for(int i=1;i<=n;i++) 27 scanf("%d",&a[i].num),a[i].po=i; 28 sort(a+1,a+n+1,cmp); 29 for(int i=1;i<=n;i++) 30 b[a[i].po]=i; 31 for(int i=1;i<=n;i++) 32 cout<<a[b[i]].num<<endl; 33 }
时间: 2024-10-25 11:37:52