Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.1 kB
61
Indexable
Never
#include<stdio.h>
void swap(int *a, int *b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
void xuli(int *a, int n, int k)
{
    if(n%2 == 1 && k != 0)
    {
        printf("-1");
    }
    else if(k == 0)
    {
         int i;
         for(i = 1;i<=n;i++)
         {
             printf("%d ", a[i]);
         }
    }
    else
    { 
        
         int i;
         if(k > n/2)
         {
             printf("-1");
         }
         else
         {
             int b[1000111] = {0};
             for(i = 1;i<=n;i++)
             {
                 if(b[i] == 0)
                 { 
                    swap(&a[i], &a[i+k]);
                    b[i] = 1;
                    b[i+k] = 1;
                 }
                
             }
             for(i = 1;i<=n;i++)
             {
                 printf("%d ", a[i]);
             }
         }
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    int a[1000111];
    int i;
    a[0] = 0;
    for(i = 1;i<=n;i++)
    {
        a[i] = i;
    }
    int k;
    scanf("%d", &k);
    xuli(a,n,k);
    return 0;
}