当前位置:网站首页>重排数组
重排数组
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;
}边栏推荐
- 深度学习7 Transformer系列实例分割Mask2Former
- [C language] Pointer written test questions
- 【C语言】指针笔试题
- 如何配和弦
- Detailed explanation of visual studio debugging methods
- 《opencv学习笔记》-- 线性滤波:方框滤波、均值滤波、高斯滤波
- LVGL 8.2 Draw label with gradient color
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
- Data Lake (13): spark and iceberg integrate DDL operations
- When synchronized encounters this thing, there is a big hole, pay attention!
猜你喜欢

Node mongodb installation

TechSmith Camtasia studio 2022.0.2 screen recording software

Codeforce:c. sum of substrings

Introduction to modern control theory + understanding

为什么国产手机用户换下一部手机时,都选择了iPhone?

Preliminary exploration of flask: WSGI

Query optimizer for SQL optimization

Is BigDecimal safe to calculate the amount? Look at these five pits~~

LVGL 8.2 LED

IO流:节点流和处理流详细归纳。
随机推荐
03-存储系统
[cloud native] how can I compete with this database?
ES6 modularization
How to handle exceptions in multithreading?
Is it safe to open an account online for stock speculation? Will you be cheated.
Openresty current limiting
The performance of major mainstream programming languages is PK, and the results are unexpected
numpy笔记
LVGL 8.2 LED
Introduction to asynchronous task capability of function calculation - task trigger de duplication
为什么国产手机用户换下一部手机时,都选择了iPhone?
No servers available for service: xxxx
微博、虎牙挺进兴趣社区:同行不同路
Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow
flutter 报错 No MediaQuery widget ancestor found.
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
openresty 重定向
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
毕业季-个人总结