Confusing Concatenations CodeChef Solution

Problem -Confusing Concatenations 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.

Confusing Concatenations CodeChef Solution in C++17

#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <string>
#include <queue>
#include <limits>
#include <algorithm>
#include <cmath>
#include <climits>
#include <numeric>
#define ll long long
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
using namespace std;
void solve() {
	int n; cin>>n;
	int c[n], a[n];
	for(int i=0;i<n;i++) {
		cin>>c[i];
		a[i] = c[i];
	}
	sort(a, a+n);
	if(c[0] == a[n-1]) {
		cout<<-1<<endl;
	}
	else {
		vector<int> f, s;
		int flag1 = 1, flag2 = 0;
		for(int i=0;i<n;i++) {
			if(flag1) {
				if(c[i] == a[n-1]) {
					flag1 = 0; flag2 = 1;
				}
				else {
					f.push_back(c[i]);
				}
			}
			if(flag2) {
				s.push_back(c[i]);
			}
		}
		cout<<f.size()<<endl;
		for(auto e : f) cout<<e<<" ";
		cout<<endl;
		cout<<s.size()<<endl;
		for(auto e : s) cout<<e<<" ";
		cout<<endl;
	}
	return;
}

int main() {

#ifndef ONLINE_JUDGE
	//for getting input from input.txt
	freopen("input.txt", "r", stdin);
	//for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	
	//YOUR CODE GOES HERE

	int tt; cin>>tt;
	
	while(tt--) {
		// cout<<"hi "<<endl;
		solve();
	}
	return 0;
}

Confusing Concatenations CodeChef Solution in C++14

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    ll crr[n];
	    ll mx=INT_MIN;
	    ll index=0;
	    for(int i=0; i<n; i++)
	    {
	        cin>>crr[i];
	        mx=max(mx,crr[i]);
	    }
	    for(int i=0; i<n; i++)
	    {
	        if(mx==crr[i])
	        {
	            index=i;
	            break;
	        }
	    }
	    if(index==0)
	    {
	        cout<<-1<<endl;
	        continue;
	    }
	    cout<<index<<endl;
	    for(int i=0; i<index; i++)
	    {
	        cout<<crr[i]<<" ";
	    }
	    cout<<endl;
	    cout<<n-index<<endl;
	    for(int i=index; i<n; i++)
	    {
	        cout<<crr[i]<<" ";
	    }
	    cout<<endl;
	}
}

Confusing Concatenations CodeChef Solution in PYTH 3

# cook your dish here
for t in range(int(input())):
    n = int(input())
    c = [int(i) for i in input().split()]
    m = max(c)
    for i in range(len(c)):
        if c[i] == m:
            x = i
    if x == 0:
        print(-1)
        continue
    print(x)
    for i in range(x):
        print(c[i], end = " ")
    print()
    print(len(c)-x)
    for i in range(len(c)-x):
        print(c[x+i], end = " ")
    print()

Confusing Concatenations CodeChef Solution in C

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d",&t);
    long int n;
    while(t--){
        scanf("%ld",&n);
        long int c[n];
        int j,k=0;
        for(int i=0;i<n;i++){
            scanf("%ld",&c[i]);
        }
        for(j=1;j<n;j++){
	        if(c[j]>c[0]){
	            k++;
	            break;
	        }
	    }
	    if(k){
	    printf("%ld\n",j);
	    for(int i=0;i<j;i++){
	        printf("%ld ",c[i]);
	    }
	    printf("\n");
	    printf("%ld\n",n-j);
	    for(int i=j;i<n;i++){
	        printf("%ld ",c[i]);
	    }
	    printf("\n");
	    }
	    else{
	        printf("-1\n");
	    }
	}
	return 0;
}

Confusing Concatenations 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
{
    static Scanner in = new Scanner(System.in);
	public static void main (String[] args) throws java.lang.Exception
	{
		int t = in.nextInt();
		while(t-- > 0){
		    int n = in.nextInt();
		    int[] a = new int[n];
		    for(int i = 0; i < n; i++){
		        a[i] = in.nextInt();
		    }
		    boolean flag = false;
		    int s = a[0];
		    int idx = -1;
		    for(int i = 1; i < n; i++){
		        if(a[i] > s){
		            flag = true;
		            idx = i;
		            break;
		        }
		    }
		    StringBuilder b=new StringBuilder();
            StringBuilder c=new StringBuilder();
		    
		    if(!flag){
		        System.out.println(-1);
		    }else{
		        System.out.println(idx);
		        for(int i = 0; i < idx; i++){
		            b.append(a[i]);
		            b.append(" ");
		        }
		        System.out.println(b.toString());
		        System.out.println(n - idx);
		        for(int i = idx; i < n; i++){
		            c.append(a[i]);
		            c.append(" ");
		        }
		        System.out.println(c.toString());
		    }
		    
		}
	}
}

Confusing Concatenations CodeChef Solution in PYPY 3

t = int(input())
for _ in range(t):
    n = int(input())
    C = list(map(int, input().split()))
    A = [C[0]]
    B = []
    current = 0

    currentMax = C[0]

    # 0: mang A
    # 1: mang B
    for i in range(1, n):
        if C[i] < C[i-1]:
            if current == 0:
                A.append(C[i])
                currentMax = max(currentMax, C[i])
            else:
                B.append(C[i])
                currentMax = max(currentMax, C[i])
        else:
            if C[i] > currentMax:
                current = 1-current
                if current == 0:
                    A.append(C[i])
                    currentMax = C[i]
                else:
                    B.append(C[i])
                    currentMax = C[i]
            else:
                if current == 0:
                    A.append(C[i])
                    currentMax = max(currentMax, C[i])
                else:
                    B.append(C[i])
                    currentMax = max(currentMax, C[i])
    if A == [] or B == []:
        print(-1)
    else:
        print(len(A))
        print(*A)
        print(len(B))
        print(*B)

Confusing Concatenations CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	N = int(raw_input())
	st = raw_input().split()
	C = []
	for x in st:
		C.append(int(x))
	# erndfor x
	n = C[0]
	A = [n]
	p = 1
	while (p < N) and (C[p] < n):
		A.append(C[p])
		p += 1
	# endwhile
	if p == N:
		print '-1'
	else:
		sz = len(A)
		print sz
		st = ''
		for x in A:
			st += str(x) + ' '
		# endfor x
		print st
		n = N-sz
		print n
		st = ''
		while p < N:
			st += str(C[p]) + ' '
			p += 1
		# endwhile
		print st
	# endif
# endfor i

Confusing Concatenations CodeChef Solution in C#

using System;
using System.Text;

public class Test
{
	public static void Main()
	{
		// your code goes here
		int n = int.Parse(Console.ReadLine());
		while (n-- > 0)
		{
			int len = int.Parse(Console.ReadLine());
			string[] str = Console.ReadLine().Split();
			int[] arr = new int[len];
			for (int i = 0; i < len; i++)
				arr[i] = int.Parse(str[i]);

			int index = -1;
			for (int i = 1; i < arr.Length; i++)
			{
				if (arr[i] > arr[0])
				{
					index = i;
					break;
				}
			}
			



			if (index == -1)
				Console.WriteLine(index);
			else
			{
				StringBuilder st = new StringBuilder("");
				StringBuilder kt = new StringBuilder("");

				for (int i = 0; i < index; i++)
					st.Append(arr[i] + " ");

				for (int i = index; i < arr.Length; i++)
					kt.Append(arr[i] + " ");
				Console.WriteLine(index);

				Console.WriteLine(st);
				Console.WriteLine(arr.Length - index);

				Console.WriteLine(kt);
			}
		}
	}
}

Confusing Concatenations CodeChef Solution in NODEJS

process.stdin.resume();
    process.stdin.setEncoding('utf8');
    
    // your code goes here
    let input = '' ;
    process.stdin.on('data', function(chunk) {
        input += chunk
    });
    
    process.stdin.on('end', function(chunk) {
        const [n,...arr]= input.split('\n');
        confuseConcat(parseInt(n), arr) ;
    }) ;
    
    function confuseConcat(t, arr) {
        let index=0;
        while(t--) {
            let n = arr[index];
            n = parseInt(n);
            let c = arr[++index].split(' ');
            let ar1=[], ar2=[], max= Number.NEGATIVE_INFINITY, maxIndex=-1;
            for (let i=0; i<n; i++) {
                c[i] = parseInt(c[i]);
                if (max < c[i]) {
                    max = c[i];
                    maxIndex=i;
                }
            }
            if (c[0] === max) {
                console.log(-1);
            }
            else {
                if (c[n-1] === max) {
                    ar2.push(max);
                    c.pop();
                    //printAns(c, ar2, n);

                    console.log(n-1);
                    let str='';
                    for (let i=0; i<=c.length-1; i++) {
                        if (i === 0) {
                            str = c[i];
                            continue;
                        }
                        str = str + ' ' + c[i];
                    }
                    console.log(str);
                    console.log(1);
                    console.log(ar2[0]);
                }
                else {
                    let point= maxIndex;
                    // for (let i=n-1; i>=0; i--) {
                    //     if (c[i] === max) {
                    //         point = i;
                    //         break;
                    //     }
                    // }
                    //printAns(c, point, n, true);
                    console.log(point);
                    let str='';
                    for (let i=0; i<point; i++) {
                        if (str === '') {
                            str += c[i];
                            continue;
                        }
                        str = str + ' ' + c[i];
                    }
                    console.log(str);
                    console.log(n-point);
                    let str2='';
                    for (let i=point; i<n; i++) {
                        if (str2 === '') {
                            str2 += c[i];
                            continue;
                        }
                        str2 = str2 + ' ' + c[i];
                    }
                    console.log(str2);
                }
            }
            
            index++;
        }
    }

Confusing Concatenations CodeChef Solution in GO

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	scanner.Scan()
	T, _ := strconv.Atoi(scanner.Text())
	for ; T > 0; T-- {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		flag := false
		var Q int
		for i := 2; i <= n; i++ {
			if a[i] > a[1] {
				flag = true
				Q = i
				break
			}
		}
		if !flag {
			fmt.Fprintln(out, -1)
			continue
		}
		fmt.Fprintln(out, Q-1)
		for i := 1; i < Q; i++ {
			fmt.Fprint(out, a[i], " ")
		}
		fmt.Fprintln(out)
		fmt.Fprintln(out, n-Q+1)
		for i := Q; i <= n; i++ {
			fmt.Fprint(out, a[i], " ")
		}
		fmt.Fprintln(out)
	}
}
Confusing Concatenations CodeChef Solution Review:

In our experience, we suggest you solve this Confusing Concatenations 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 Confusing Concatenations CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Confusing Concatenations 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 *