문제 링크입니다: https://www.acmicpc.net/problem/10804
10804번: 카드 역배치
1부터 20까지 오름차순으로 놓인 카드들에 대해, 입력으로 주어진 10개의 구간 순서대로 뒤집는 작업을 했을 때 마지막 카드들의 배치를 한 줄에 출력한다.
www.acmicpc.net
N이 20이기 때문에 입력받을 때마다 배열을 직접 바꿔줘도 무방한 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MAX = 20 + 1; | |
int arr[MAX]; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
for (int i = 1; i < MAX; i++) | |
{ | |
arr[i] = i; | |
} | |
for (int i = 0; i < 10; i++) | |
{ | |
int left, right; | |
cin >> left >> right; | |
for (int j = left, k = 0; j <= (left + right) / 2; j++, k++) | |
{ | |
swap(arr[j], arr[right - k]); | |
} | |
} | |
for (int i = 1; i < MAX; i++) | |
{ | |
cout << arr[i] << " "; | |
} | |
cout << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 11328번 Strfry (0) | 2020.03.02 |
---|---|
백준 1267번 핸드폰 요금 (0) | 2020.03.01 |
백준 2108번 통계학 (0) | 2020.02.24 |
백준 11375번 열혈강호 (0) | 2020.02.23 |
백준 9322번 철벽 보안 알고리즘 (0) | 2020.02.19 |