zoukankan      html  css  js  c++  java
  • Sort 对下标进行排序

    很久之前看到了  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("
    ");
        return 0 ; 
    }
    没有梦想,何谈远方
  • 相关阅读:
    js中的字符串
    JSOP
    jq总结1
    jq总结
    诗和远方-志
    诗和远方-感
    js判断变量是否为空字符串、null、undefined
    判断js对象是否为空
    诗和远方-悟
    深复制
  • 原文地址:https://www.cnblogs.com/zyue/p/4007476.html
Copyright © 2011-2022 走看看