Divisible

Problem

You are given an array A of size N that contains integers. Here,N  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 11.

C Solution:
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int main() {
  4.    int N,i,mid,esum=0,osum=0;
  5.    scanf("%d",&N);
  6.    int A[N];
  7.    for(i=0;i<N;i++){
  8.       scanf("%d",&A[i]);
  9.    }
  10.    mid=(N/2)-1;
  11.    for(i=0;i<=mid;i++){
  12.       check:if(A[i]>9){
  13.          A[i]=A[i]/10;
  14.          goto check;
  15.       }
  16.       else{
  17.          A[i]=A[i];
  18.       }
  19.    }
  20.    for(i=mid+1;i<N;i++){
  21.       A[i]=A[i]%10;
  22.    }
  23.    for(i=0;i<N;i++){
  24.       if(i%2==0)
  25.          esum+=A[i];
  26.       else
  27.        osum+=A[i];
  28.    }
  29.    int div=osum-esum;
  30.    if(div%11==0)
  31.       printf("OUI");
  32.    else
  33.       printf("NON");
  34.    return 0;
  35. }

Python Solution:

  1. n = int(input())
  2. A=[x for x in input().split()]
  3. lst = []
  4. last_lst=[]
  5. count=0
  6. for i in A:
  7.      if count < n/2:
  8.           lst.append(i[0])
  9.           count +=1
  10.      else:
  11.           last_lst.append(i[-1])
  12.           count+=1
  13. res = lst + last_lst
  14. val = "".join(res)
  15. if int(val)%11==0:
  16.      print("OUI")
  17. else:
  18.      print("NON")
Note:
       We Are Providing Every Content in this Blog Inspired From Many People and Provide it Open To All People Who Are Willing Gain Some Stuff in Computer Science.

Comment Below👇 If You Find Better Solution Than Above Solution.