当前位置:网站首页>重排数组
重排数组
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;
}
边栏推荐
- Combined with case: the usage of the lowest API (processfunction) in Flink framework
- Quick introduction to automatic control principle + understanding
- IO流:节点流和处理流详细归纳。
- When synchronized encounters this thing, there is a big hole, pay attention!
- Data Lake (13): spark and iceberg integrate DDL operations
- LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
- Openresty redirection
- C language set operation
- Node mongodb installation
- Ali was laid off employees, looking for a job n day, headhunters came bad news
猜你喜欢
5G电视难成竞争优势,视频资源成中国广电最后武器
An overview of 2D human posture estimation
Helix Swarm中文包发布,Perforce进一步提升中国用户体验
Transplant tinyplay for imx6q development board QT system
10. (map data) offline terrain data processing (for cesium)
They are all talking about Devops. Do you really understand it?
No servers available for service: xxxx
Halo effect - who says that those with light on their heads are heroes
MP3是如何诞生的?
近一亿美元失窃,Horizon跨链桥被攻击事件分析
随机推荐
C language course design questions
The performance of major mainstream programming languages is PK, and the results are unexpected
Kubernets pod exists finalizers are always in terminating state
UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
MP3是如何诞生的?
LVGL 8.2 LED
曝光一下阿里的工资待遇和职位级别
Is BigDecimal safe to calculate the amount? Look at these five pits~~
【学习笔记】拟阵
【C语言】指针笔试题
LVGL 8.2 text shadow
On the implementation plan of MySQL explain
Transplant tinyplay for imx6q development board QT system
LVGL 8.2 Sorting a List using up and down buttons
What are the concepts of union, intersection, difference and complement?
Programmer turns direction
C language achievement management system for middle school students
Luo Gu - some interesting questions
Graduation season - personal summary
%f格式符