CF 136A Presents

http://codeforces.com/problemset/problem/136/A

题意 :就是输入很多数字,第 i 个数字 pi 代表着第 i 个人的礼物给了第 pi 个人,而让你输出的数字中代表的就是 谁的礼物给了第 i 个人

思路 :就这道题我竟然脑子锈了很久才想出来。。。

#include<iostream>
#include<algorithm>
#include<cstdio>
struct node
{
    int give ;
    int given ;
}a[110] ;
using namespace std ;
bool cmp(struct node s,struct node t)
{
    return s.given<t.given ;
}
int main()
{
    int n ;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i = 1 ; i <= n ; i++)
        {
            scanf("%d",&a[i].given) ;
            //2 3 4 1
            a[i].give = i ;
            //1 2 3 4
        }
        sort(a+1,a+n+1,cmp) ;
        for(int i = 1 ; i < n ; i++)
        printf("%d ",a[i].give) ;
        printf("%d
",a[n].give) ;
        //4 1 2 3
    }
    return 0 ;
}
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3417004.html