当前位置:网站首页>重排数组
重排数组
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;
}
边栏推荐
- Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
- 如何配和弦
- 如何搭建一支搞垮公司的技术团队?
- C language course design questions
- leecode学习笔记-约瑟夫问题
- 毕业季-个人总结
- [information retrieval] experiment of classification and clustering
- Is BigDecimal safe to calculate the amount? Look at these five pits~~
- 自动控制原理快速入门+理解
- 关于FPGA底层资源的细节问题
猜你喜欢
《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
When synchronized encounters this thing, there is a big hole, pay attention!
对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
Node mongodb installation
程序员自曝接私活:10个月时间接了30多个单子,纯收入40万
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Leecode learning notes - Joseph problem
Luo Gu - some interesting questions 2
自动控制原理快速入门+理解
Redis publish and subscribe
随机推荐
Redis 發布和訂閱
Gin integrated Alipay payment
PLC Analog input analog conversion FC s_ ITR (CoDeSys platform)
leetcode:6109. Number of people who know the secret [definition of DP]
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
When synchronized encounters this thing, there is a big hole, pay attention!
What are the concepts of union, intersection, difference and complement?
A collection of classic papers on convolutional neural networks (deep learning classification)
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Comment configurer un accord
LVLG 8.2 circular scrolling animation of a label
5G电视难成竞争优势,视频资源成中国广电最后武器
Detailed explanation of visual studio debugging methods
对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
Partial modification - progressive development
LVGL 8.2 keyboard
How to build a technical team that will bring down the company?
Quick introduction to automatic control principle + understanding
Xcode abnormal pictures cause IPA packet size problems
leecode学习笔记-约瑟夫问题