CodeForces 136 A.Presents(水~)

解决一个简单的编程问题:n个人互相送礼,已知每个人送礼的对象,通过编程找出每个人收到礼物的来源。使用C++实现,核心思路为创建数组进行映射。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

n个人互相送礼,第i个人送第pi个人礼物,每个人只会送出一份礼收到一份礼,问第i个人收到的礼物是谁送的

Input

第一行一整数n表示人数,之后n个整数pi表示第i个人送礼物对象(1n100)

Output

输出n个整数,第i个数表示送第i个人礼物的人

Sample Input

4

2 3 4 1

Sample Output

4 1 2 3

Solution

水题,拿个数组映射一下即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int n,a[maxn];
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
        {
            int b;
            scanf("%d",&b);
            a[b]=i;
        }
        for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值