Divisible

PHOTO EMBED

Sat Apr 30 2022 12:22:31 GMT+0000 (Coordinated Universal Time)

Saved by @GreenMark #javascript

// Divisible
// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
   main(stdin_input);
});

function main(input) {
    var data= input.toString().split("\n");

    process.stdout.write(divisible(data[1], parseInt(data[0])));
           // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail



// Write your code here
// Sample code to perform I/O:
//Enter your code here

function divisible(input,n) {
   
    const arr = input.split(" ");
    let firstHalf = arr.slice(0,n/2);
    let secondHalf = arr.slice(n/2, n);

   
    let sumOdd = 0;
    let sumEven =0;

    let number= "";
    for (let i=0; i<n/2; i++) {
        number = number + firstHalf[i].substr(0,1);
        
    }

    for (let i=0; i<n/2; i++) {
        number = number + secondHalf[i].substr(secondHalf[i].length-1,1);
        
    }

    for (let i=0; i<n; i++) {
        let digit = parseInt(number.substr(i,1),10);
   
        if (i % 2 == 0) {
            sumOdd = sumOdd + digit;
        } else {
            sumEven = sumEven + digit;
        }
    } 

   
    if ((sumOdd - sumEven) % 11 == 0) {
        return 'OUI'
    } else { return "NON"};
    

    

}
    
    
content_copyCOPY

Problem You are given an array of size that contains integers. Here, is an even number. You are required to perform the following operations: Divide the array of numbers in two equal halves Note: Here, two equal parts of a test case are created by dividing the array into two equal parts. Take the first digit of the numbers that are available in the first half of the array (first 50% of the test case) Take the last digit of the numbers that are available in the second half of the array (second 50% of the test case) Generate a number by using the digits that have been selected in the above steps Your task is to determine whether the newly-generated number is divisible by . Input format First line: A single integer denoting the size of array Second line: space-separated integers denoting the elements of array Output format If the newly-generated number is divisible by , then print . Otherwise, print . Constraints Sample Input 6 15478 8452 8232 874 985 4512 Save Sample Output OUI

https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/divisibe-or-2d8e196a/