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 ; 
    }
    没有梦想,何谈远方
  • 相关阅读:
    初识CC_MVPMatrix
    opengl启动过程
    http协议
    sockt套接字编程
    lua元表
    Codeforces 1203F1 Complete the Projects (easy version)
    CodeForces 1200E Compress Words
    CodeForces 1200D White Lines
    HDU 6656 Kejin Player
    HDU 6651 Final Exam
  • 原文地址:https://www.cnblogs.com/zyue/p/4007476.html
Copyright © 2011-2022 走看看