Rohyoohyun / C

0 stars 0 forks source link

10811 바구니 뒤집기 #44

Open Rohyoohyun opened 2 months ago

Rohyoohyun commented 2 months ago
#include <stdio.h>

int main(){
    int n, m;
    scanf("%d %d", &n, &m);

    int arr[n];
    for (int i=0; i<n; i++)
        arr[i] = i+1;

    for (int i=0; i<m; i++){
        int temp, a, b;
        scanf("%d %d", &a, &b);
        for (int j=0; j< (b-a)/2+1; j++){
            temp = arr[a+j-1];
            arr[a+j-1] = arr[b-1-j];
            arr[b-j-1] = temp;
        }
    }

    for (int i=0; i<n; i++)
        printf("%d ", arr[i]);

    return 0;
}