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[] ;
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 = ; i <= n ; i++)
{
scanf("%d",&a[i].given) ;
//2 3 4 1
a[i].give = i ;
//1 2 3 4
}
sort(a+,a+n+,cmp) ;
for(int i = ; i < n ; i++)
printf("%d ",a[i].give) ;
printf("%d\n",a[n].give) ;
//4 1 2 3
}
return ;
}
上一篇:iOS开发技巧系列---使用链式编程和Block来实现UIAlertView


下一篇:ios新特征 ARC详解