하다보니
10804번-카드 역배치 본문
#include<bits/stdc++.h>
using namespace std;
int arr[21];
void reverse(int a, int b) {
for (int i = 0; i < (b - a + 1) / 2; i++) {
swap(arr[a + i], arr[b - i]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i < 21; i++) arr[i] = i;
for (int i = 0; i < 10; i++) {
int a, b;
cin >> a >> b;
reverse(a, b);
}
for (int i = 1; i < 21; i++) cout << arr[i] << ' ';
}
'알고리즘 풀이 > 백준' 카테고리의 다른 글
3273번-두 수의 합 (0) | 2022.01.13 |
---|---|
1475번-방 번호 (0) | 2022.01.13 |
2577번-숫자의 개수 (0) | 2022.01.13 |
10808번-알파벳 개수 (0) | 2022.01.13 |
[백준 2576번]홀수 (0) | 2022.01.10 |