当前位置:网站首页>重排数组
重排数组
2022-07-04 13:32:00 【Zaltana】
给定一个大小为N的数组arr[],其中每个元素都在0到N- 1的范围内。重新排列给定数组,使arr[i]变为arr[arr[i]]。比如arr[] = {4,0,2,1,3}, 则arr[arr[0]] = arr[4]= 3, arr[arr[1]] =arr[0] = 4。输出新数组。
不考虑不合理的输入等特殊情况。
格式.
输入格式:第一行输入数组长度N,第二行输入数组元素,整型,空格分隔。
输出格式:输出整型,空格分隔。
样例
输入: 5
4 0 2 1 3
输出: 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;
}边栏推荐
- TechSmith Camtasia studio 2022.0.2 screen recording software
- Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
- LVLG 8.2 circular scrolling animation of a label
- openresty 重定向
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- es6模块化
- 进制乱炖
- Graduation season - personal summary
- SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
- 炒股网上开户安全吗?会不会被骗。
猜你喜欢
![LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路](/img/4a/6763e3fbdeaf9de673fbe8eaf96858.png)
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
![Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding](/img/4a/6763e3fbdeaf9de673fbe8eaf96858.png)
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding

Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)

How to match chords

深度学习 神经网络案例(手写数字识别)
![leetcode:6109. Number of people who know the secret [definition of DP]](/img/95/03e2606b249f26db052cf5075041c1.png)
leetcode:6109. Number of people who know the secret [definition of DP]
![[differential privacy and data adaptability] differential privacy code implementation series (XIV)](/img/de/c053f376fe90c2697ffc640fab57e8.jpg)
[differential privacy and data adaptability] differential privacy code implementation series (XIV)

IO流:节点流和处理流详细归纳。

《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波

关于FPGA底层资源的细节问题
随机推荐
On the implementation plan of MySQL explain
Helix Swarm中文包发布,Perforce进一步提升中国用户体验
深度学习7 Transformer系列实例分割Mask2Former
近一亿美元失窃,Horizon跨链桥被攻击事件分析
Leecode learning notes - Joseph problem
Openresty current limiting
Ffmpeg Visual Studio development (IV): audio decoding
Detailed explanation of visual studio debugging methods
When synchronized encounters this thing, there is a big hole, pay attention!
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
LVGL 8.2 text shadow
各大主流编程语言性能PK,结果出乎意料
Combined with case: the usage of the lowest API (processfunction) in Flink framework
[differential privacy and data adaptability] differential privacy code implementation series (XIV)
leetcode:6109. Number of people who know the secret [definition of DP]
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
Redis 解决事务冲突之乐观锁和悲观锁
Openresty redirection
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
[information retrieval] experiment of classification and clustering