분류 전체보기
-
10804) 카드 역배치 c++백준코딩일기 2020. 10. 17. 09:39
문제 ) www.acmicpc.net/problem/10804 10804번: 카드 역배치 1부터 20까지 오름차순으로 놓인 카드들에 대해, 입력으로 주어진 10개의 구간 순서대로 뒤집는 작업을 했을 때 마지막 카드들의 배치를 한 줄에 출력한다. www.acmicpc.net 풀이 ) 카드가 1~20 이므로 배열의 크기를 21로 정했다. 1). swap 함수는 서로의 자리를 바꾸는 형태로 첫 번째 예시에 나온 5(begin) ~ 10(end)을 바꾸는 거라면, 5 10 6 9 7 8 총 3번(= (10-5)/2 +1 )의 swap 을 해야한다. j=0 ... (10-5)/2+1 까지 for 문을 돌린다. 이때, 1을 더하는 이유는 나머지가 있다면 한 번 더 돌아야하기 때문이다. j=0 이면 swap(card..