Xor Permutation CodeChef Solution

Problem -Xor Permutation CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Xor Permutation CodeChef Solution in C++17

#include <iostream>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	int t;
	cin>>t;
	while (t--)
	{
	    ll n;
	    cin>>n;
	    if (n==3)
	    {
	        cout<<-1<<endl;
	    }
	    else if (n==4)
	    {
	        cout<<1<<" "<<2<<" "<<4<<" "<<3<<endl;
	    }
	    else if (n==5)
	    {
	        cout<<5<<" "<<1<<" "<<2<<" "<<4<<" "<<3<<endl;
	    }
	    else if (n>5 && n<=10)
	    {
	        for (int i=n; i>4; i--)
	        {
	            cout<<i<<" ";
	        }
	        cout<<1<<" "<<2<<" "<<4<<" "<<3<<endl;
	    }
	    else 
	    {
	        cout<<"10 9 8 7 6 5 1 2 4 3 ";
	        for (int i=11; i<=n; i++)
	        {
	            cout<<i<<" ";
	        }
	        cout<<endl;
	    }
	}
	return 0;
}

Xor Permutation CodeChef Solution in C++14


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define Time cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#define pb push_back
#define mp make_pair
#define line cout << endl;
#define ff first
#define ss second
#define vi vector<int>
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define printv(v)                      \
  for (int i = 0; i < (v.size()); i++) \
  {                                    \
    cout << v[i] << " ";               \
  }                                    \
  line;
#define onesbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define sp(x, y) fixed << setprecision(y) << x
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)
#define tk(x) \
  int x;      \
  cin >> x;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
#define debug(x)     \
  cerr << #x << " "; \
  _print(x);         \
  cerr << endl;
#else
#define debug(x)
#endif
template <class T>
void _print(T t)
{
  cerr << t;
}

template <class T, class V>
void _print(pair<T, V> p)
{
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  cerr << "}";
}

template <class T>
void _print(vector<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(vector<vector<T>> v)
{
  cerr << "[\n";
  for (int l = 0; l < v.size(); l++)
  {
    {
      for (int k = 0; k < v[l].size(); k++)
        cerr << v[l][k] << " ";
    }
    cerr << "\n";
  }
  cerr << "]";
}

template <class T, class V>
void _print(map<T, V> v)
{
  cerr << "[ ";
  for (auto i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(set<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

const long long inf = 1e18;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

int numbit(int x)
{
    int ans = 0;
    while (x > 0)
    {
        x = x >> 1;
        ans++;
    }
    return ans;
}

int setbit(int x)
{
    int ans = 0;
    while (x > 0)
    {
        if (x & 1)
        {
            ans++;
        }
        x = x >> 1;
    }
    return ans;
}

bool isValid(string s)
{
  int len = s.size();
  for (int i = 0; i < len / 2; i++)
  {
    if (s[i] != s[len - 1 - i])
      return false;
  }
  return true;
}

void rotateMatrix(vector<vector<int>> &v, int n)
{
  for (int i = 0; i < n / 2; i++)
  {
    for (int j = i; j < n - i - 1; j++)
    {
      int ptr = v[i][j];
      v[i][j] = v[n - 1 - j][i];
      v[n - 1 - j][i] = v[n - 1 - i][n - 1 - j];
      v[n - 1 - i][n - 1 - j] = v[j][n - 1 - i];
      v[j][n - 1 - i] = ptr;
    }
  }
}

vector<bool> is_prime(10001, 1);
vector<int> primes;

void seive()
{
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < 10001; i++)
  {
    if (is_prime[i])
    {
      primes.push_back(i);
      for (int j = i + i; j < 10001; j += i)
      {
        is_prime[j] = 0;
      }
    }
  }
}

ll expo (ll x,ll n){
    ll result=1;
    while (n) {
        if (n & 1)
            result = result * x % MOD;
        n = n / 2;
        x = x * x % MOD;
    }
    return result;
}



int32_t main() {
  ll t; cin >> t;
  // seive();
  while (t--) {
    // ll n,m,sum=0,k; cin>>n;
    // ll l=1,r=n;
      int n;
      cin>>n;
      if(n==3){
        cout<<-1<<endl;
      }else {
        cout<<"1 3 4 2 ";

        for (ll i = 5; i <=n; i++)
        {
          /* code */
          cout<<i<<" ";
        }

        cout<<endl;
        
      }
   
  }
  return 0;
}

// 1b 4d

Xor Permutation CodeChef Solution in PYTH 3

# cook your dish here
t = int(input())
for _ in range(0,t):
    n = int(input())
    lst = [1,2,4,3]
    if(n==3):
        print(-1)
        continue
    else:
        for i in range(5,n+1):
            lst.insert(0,i)
    print(*lst)
            

Xor Permutation CodeChef Solution in C

#include <stdio.h>

int main() 
{
	int u;
	scanf("%d", &u);
	while(u--)
	{
	    int n;
	    scanf("%d", &n);
	    if(n == 3)
	    {
	        printf("-1\n");
	    }
	    else
	    {
	        printf("1 3 4 2 ");
	        for(int i = 5; i <= n; i++)
	        {
	            printf("%d ", i);
	        }
	        printf("\n");
	    }
	}
	return 0;
}

Xor Permutation CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
		int tt=Integer.parseInt(reader.readLine().trim());
		test:
		while(tt-->0){
		    int n=Integer.parseInt(reader.readLine().trim());
		    if(n<=3){
		        writer.write("-1\n");
		    }else{
		        writer.write("1 3 4 2");
		        for(int i=5;i<=n;i++){
		            writer.write(" "+i);
		        }
		        writer.write("\n");
		    }
		}
		writer.flush();
	}
	
	private static void swap(int[] a, int i, int j){
	    int temp=a[i];
	    a[i]=a[j];
	    a[j]=temp;
	}
    
    private static int[] parseInt(String str) {
        String[] parts=str.split("\\s+");
        int[] ans=new int[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Integer.parseInt(parts[i]);
        }
        return ans;
    }

    private static long[] parseLong(String str) {
        String[] parts=str.split("\\s+");
        long[] ans=new long[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Long.parseLong(parts[i]);
        }
        return ans;
    }
}

Xor Permutation CodeChef Solution in PYPY 3

# 3142
for i in range(int(input())):
    n=int(input())
    if n==3:print(-1);continue
    for i in range(3,n+1):
        print(i,end=" ")
    print(2,1)
    

Xor Permutation CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	N = int(raw_input())
	if N == 3:
		st = '-1'
	# endif
	if N == 4:
		st = '1 2 4 3'
	# endif
	if N == 5:
		st = '1 2 4 3 5'
	# endif
	if N == 6:
		st = '6 1 2 4 3 5'
	# endif
	if N > 6:
		st = '1 2 4 3 5 7 6 '
		for k in range(8,N+1):
			st += str(k) + ' '
		# endfor k
	# endif
	print st
# endfor i

Xor Permutation CodeChef Solution in C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using System.Numerics;

public class Test
{

    public static void Main()
    {
        var t = GetInt();
        for (int i = 0; i < t; i++)
            Solve();
    }

    public static void Solve()
    {
        int n = GetInt();
        if(n == 3)
        {
            Console.WriteLine(-1);
            return;
        }
        int[] ans = new int[n];
        for(int i=0; i<n; i++)
        {
            if(i%2 == 0)
            {
                ans[i / 2] = i + 1; 
            }
            else
            {
                ans[n -i / 2 -1] = i;
            }
        }
        string ansy = String.Join(" ", ans);
#if DEBUG
        Console.Write("Answer is --------------> ");
#endif
        Console.WriteLine(ansy);
    }

    public static int GetInt() => int.Parse(Console.ReadLine());
    public static long GetLong() => long.Parse(Console.ReadLine());

    public static int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
    public static long[] GetLongArray() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();



    public static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
    public static int Gcd(int[] n) => n.Aggregate((a, b) => Gcd(a, b));

    public static bool IsBitSet(long a, int bit)
    {
        return (a & (1L << bit)) != 0;
    }
}

Xor Permutation CodeChef Solution in GO

package main

import (
	"fmt"
	"bufio"
	"strings"
	"strconv"
	"os"
)

func main() {
	var (
		t int
	)	

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)
	
	for t > 0 {
		t--
                
		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		n, _ := strconv.Atoi(ninps[0])

		arr := make([]int, n)
		
		if n == 3 {
			fmt.Println(-1)
		} else {
			for i := 1; i <= n; i++ {
				if i == 3 || i == 4 || i == 6 || i == 7 {
					if i == 3 {
						fmt.Print(4," ")
						arr[i-1] = 4
					} else if i == 4 {
						fmt.Print(3," ")
						arr[i-1] = 3
					} else if i == 6 {
						fmt.Print(7, " ")
						arr[i-1] = 7
					} else if i == 7 {
						fmt.Print(6, " ")
						arr[i-1] = 6
					}			
				} else {
				        fmt.Printf("%d ", i)
					arr[i-1] = i
				}	        	
			} 
			fmt.Println()
		}
	}	
}
Xor Permutation CodeChef Solution Review:

In our experience, we suggest you solve this Xor Permutation CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Xor Permutation CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Xor Permutation CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *