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:
- #include<stdio.h>
- #include<stdlib.h>
- int main() {
- int N,i,mid,esum=0,osum=0;
- scanf("%d",&N);
- int A[N];
- for(i=0;i<N;i++){
- scanf("%d",&A[i]);
- }
- mid=(N/2)-1;
- for(i=0;i<=mid;i++){
- check:if(A[i]>9){
- A[i]=A[i]/10;
- goto check;
- }
- else{
- A[i]=A[i];
- }
- }
- for(i=mid+1;i<N;i++){
- A[i]=A[i]%10;
- }
- for(i=0;i<N;i++){
- if(i%2==0)
- esum+=A[i];
- else
- osum+=A[i];
- }
- int div=osum-esum;
- if(div%11==0)
- printf("OUI");
- else
- printf("NON");
- return 0;
- }
Python Solution:
- n = int(input())
- A=[x for x in input().split()]
- lst = []
- last_lst=[]
- count=0
- for i in A:
- if count < n/2:
- lst.append(i[0])
- count +=1
- else:
- last_lst.append(i[-1])
- count+=1
- res = lst + last_lst
- val = "".join(res)
- if int(val)%11==0:
- print("OUI")
- else:
- 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.
Post a Comment
Post a Comment
Learn, Share and Enjoy