백준 [ALGORITHM] - 바구니 뒤집기 (10811)
2024. 4. 29. 15:47ㆍ코딩/백준 [ALGORITHM]
반응형
#include <stdio.h>
int revlst(int lst[], int a, int b) {
a = a-1;
b = b-1;
while(a < b) {
int temp = lst[a];
lst[a] = lst[b];
lst[b] = temp;
a++;
b--;
}
}
int main() {
int n, m;
int a, b;
scanf("%d %d", &n, &m);
int lst[n];
for (int i = 0; i<n; i++) {
lst[i] = i+1;
}
for (int i = 0; i<m; i++) {
int a, b;
scanf("%d %d", &a, &b);
revlst(lst, a, b);
}
for (int i = 0; i<n; i++) {
printf("%d ",lst[i]);
}
}
반응형
'코딩 > 백준 [ALGORITHM]' 카테고리의 다른 글
백준 [ALGORITHM] - 학생 번호 (1235) (0) | 2024.05.15 |
---|---|
백준 [ALGORITHM] - 별 찍기 - 7 (2444) (0) | 2024.04.29 |
백준 [ALGORITHM] - 공 바꾸기 (10813) (0) | 2024.04.29 |
백준 [ALGORITHM] - 공 넣기 (10810) (1) | 2024.04.28 |
백준 [ALGORITHM] - 문자열 (1120) (0) | 2024.04.08 |