当前位置:网站首页>重排数组
重排数组
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;
}边栏推荐
- No servers available for service: xxxx
- selenium 元素交互
- Luo Gu - some interesting questions 2
- Luo Gu - some interesting questions
- How to handle exceptions in multithreading?
- 找数字
- 现代控制理论入门+理解
- Red envelope activity design in e-commerce system
- Ffprobe common commands
- Ali was laid off employees, looking for a job n day, headhunters came bad news
猜你喜欢

Kubernets pod exists finalizers are always in terminating state

Helix swarm Chinese package is released, and perforce further improves the user experience in China

Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作

LVGL 8.2 LED

Flutter reports an error no mediaquery widget ancestor found

Why do domestic mobile phone users choose iPhone when changing a mobile phone?

近一亿美元失窃,Horizon跨链桥被攻击事件分析

Details of FPGA underlying resources

Halo effect - who says that those with light on their heads are heroes

Redis publish and subscribe
随机推荐
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
03-存储系统
Programmer turns direction
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
Redis 发布和订阅
IO flow: node flow and processing flow are summarized in detail.
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
flutter 报错 No MediaQuery widget ancestor found.
MP3是如何诞生的?
Red envelope activity design in e-commerce system
TechSmith Camtasia studio 2022.0.2 screen recording software
Ultrasonic distance meter based on 51 single chip microcomputer
Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作
Quick introduction to automatic control principle + understanding
How to handle exceptions in multithreading?
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
LVGL 8.2 List
深度学习 神经网络案例(手写数字识别)
信号处理之一阶RC低通滤波器宏指令实现(繁易触摸屏)