Menu Close

Lapindrome in C program…FcukTheCode

Nathan is a Researcher in English Literature. According to him string which when split in the middle, gives two halves having the same characters and the same frequency of each character is termed as Lapindrome. 

If there are an odd number of characters in the string, the middle character needs to be ignored and to be checked for lapindrome. can you find the lapindrome strings? 

Input:
The first line of input contains a single integer T, the number of test cases.
Each testcase is a single line containing a string S composed of only lowercase English alphabet.

Output:
For each test case, output on a separate line: if the string is a lapindrome print "YES" otherwise print "NO".
#include <stdio.h>
#include<string.h>
int main()
{   int i=0,T=0;
    scanf("%d",&T);
    for(i=0;i<T;i++){
        int arr1[26],arr2[26];
        memset(arr1,0,26*sizeof(int));
        memset(arr2,0,26*sizeof(int));
        char S[20];scanf("%s",S);
        int j=0,k=strlen(S)-1,flag=0;
            while(j<k){
                arr1[S[j]-'a']++;
                arr2[S[k]-'a']++;
                j++;
                k--;
            }
            for (j=0;j<26;j++){
                if(arr1[j]!=arr2[j]){printf("NO\n");flag=1;break;}
            }
            if(flag==0){printf("YES\n");}
    }
	return 0;
}

INPUT_1:
 6
gaga  abcde  rotor  xyzxy  abbaab  ababc

OUTPUT:
YES
NO
YES
YES
NO
NO


INPUT_2:
 5
ghfgh  malayalam  gogo  roor  caffac

OUTPUT:
YES
YES
YES
YES
YES


ILLUSTRATION:

EXECUTED USING GCC LINUX