码迷,mamicode.com
首页 > 其他好文 > 详细

Sort 对下标进行排序

时间:2014-10-06 01:07:09      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   for   sp   div   c   

很久之前看到了  lrj用到了这个技巧,今天才来验证了一下 ,  b为下表,在保证 a数组不变的额情况下知道  a数组的顺序。

代码如下

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

int a[10000];
int b[10000];
bool cmp(int c, int b)
{
    return a[c] < a[b];
}
int main(){
    int n; 
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++)
        scanf("%d",&a[i]);
    for(int j = 1;j <= n;j ++)
        b[j] = j ; 
    sort(b+1,b+n+1,cmp);
    for(int j = 1;j <= n;j ++)
        printf("%d ",b[j]);
    printf("\n");
    return 0 ; 
}

 

Sort 对下标进行排序

标签:style   blog   color   io   os   for   sp   div   c   

原文地址:http://www.cnblogs.com/zyue/p/4007476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!