1015๋ฒ: ์์ด ์ ๋ ฌ
P[0], P[1], ...., P[N-1]์ 0๋ถํฐ N-1๊น์ง(ํฌํจ)์ ์๋ฅผ ํ ๋ฒ์ฉ ํฌํจํ๊ณ ์๋ ์์ด์ด๋ค. ์์ด P๋ฅผ ๊ธธ์ด๊ฐ N์ธ ๋ฐฐ์ด A์ ์ ์ฉํ๋ฉด ๊ธธ์ด๊ฐ N์ธ ๋ฐฐ์ด B๊ฐ ๋๋ค. ์ ์ฉํ๋ ๋ฐฉ๋ฒ์ B[P[i]] = A[i]์ด๋ค. ๋ฐฐ์ด A๊ฐ ์ฃผ
www.acmicpc.net
// Copyright ยฉ 2021 ์์ฃผํ. All rights reserved. // // https://www.acmicpc.net/problem/1015 // BOJ1015 ์์ด ์ ๋ ฌ #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); int A; //๋ฐฐ์ด์ ํฌ๊ธฐ cin >> A; vector<int>arr_value; vector<int>arr_index; vector<int>ans; for (int i = 0; i < A; i++) { int number; cin >> number; arr_value .push_back(number); arr_index.push_back(number); } sort(arr_index.begin(), arr_index.end()); for (int i = 0; i < A; i++) { for (int j = 0; j < A; j++) { if (arr_value[i] == arr_index[j]) { ans.push_back(j); arr_index[j] = -1; //๋จผ์ ๋์ค๋ ๋๊ฐ์ ๊ฐ์ ์ธ๋ฑ์ค๋ก ํ๋จํ ์ ์๊ธฐ๋๋ฌธ์ ๊ฐ ๋ณ๊ฒฝ. break; } } } for (int i = 0; i < A; i++) { cout << ans[i]<<" "; } }
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1026๋ฒ - ๋ณด๋ฌผ (0) | 2021.10.16 |
---|---|
[๋ฐฑ์ค,c++] 10174๋ฒ - ํฐ๋ฆฐ๋๋กฌ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 10159๋ฒ - ์ ์ธ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1012๋ฒ - ์ ๊ธฐ๋ ๋ฐฐ์ถ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1010๋ฒ - ๋ค๋ฆฌ ๋๊ธฐ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1009๋ฒ - ๋ถ์ฐ์ฒ๋ฆฌ (0) | 2021.10.16 |
๋๊ธ