当前位置:网站首页>Rearrange array
Rearrange array
2022-07-04 15:35:00 【Zaltana】
Given a size of N Array of arr[], Each of these elements is in 0 To N- 1 Within the scope of . Rearrange the given array , send arr[i] Turn into arr[arr[i]]. such as arr[] = {4,0,2,1,3}, be arr[arr[0]] = arr[4]= 3, arr[arr[1]] =arr[0] = 4. Output new array .
Do not consider unreasonable input and other special circumstances .
Format .
Input format : On the first line, enter the length of the array N, The second line inputs the array elements , integer , The blank space to separate .
Output format : Output integer , The blank space to separate .
Examples
Input : 5
4 0 2 1 3
Output : 3 4 2 0 1
#include<bits/stdc++.h>
using namespace std;
int main( )
{
int A[100], B[100], N;
scanf("%d", &N);
for(int i=0;i<N;i++)
scanf("%d", &A[i]);
for(int i=0;i<N;i++)
B[i] = A[A[i]] ;
for(int i=0;i<N;i++)
printf("%d ", B[i]);
return 0;
}
边栏推荐
猜你喜欢
They are all talking about Devops. Do you really understand it?
函数式接口,方法引用,Lambda实现的List集合排序小工具
Unity脚本常用API Day03
大神详解开源 BUFF 增益攻略丨直播
压力、焦虑还是抑郁? 正确诊断再治疗
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Understand the context in go language in an article
Unity script lifecycle day02
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
MySQL learning notes - data type (numeric type)
随机推荐
输入宽度!
web聊天室实现
Redis 解决事务冲突之乐观锁和悲观锁
MySQL学习笔记——数据类型(数值类型)
go-zero微服务实战系列(九、极致优化秒杀性能)
Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
华为云数据库DDS产品深度赋能
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
When synchronized encounters this thing, there is a big hole, pay attention!
AI做题水平已超过CS博士?
Redis的4种缓存模式分享
Go deep into the details of deconstruction and assignment of several data types in JS
[learning notes] matroid
Unity script introduction day01
Flutter reports an error no mediaquery widget ancestor found
.Net之延迟队列
Unity预制件Prefab Day04
找数字
hexadecimal
MySQL - MySQL adds self incrementing IDs to existing data tables