Funny String : HackerRank Problem Solution

Funny String : HackerRank Problem Solution

C Implementation:


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int i=0;
void reversecopy(char *s,char *v)
    {
    if(*s=='\0')
        return;
    reversecopy(s+1,v);
    v[i++]=*s;
}

int main() {

    int T,len,flag=1,j;
    char *s,*v;
    s=(char*)malloc(sizeof(char)*10000);
    v=(char*)malloc(sizeof(char)*10000);
    scanf("%d",&T);
    while(T--)
        {
        flag=1;
        scanf("%s",s);
        len=strlen(s);
        reversecopy(s,v);
        *(v+len)='\0';
        i=0;
        for(j=1;j<len;j++)
            {
            if(abs(s[j]-s[j-1])!=abs(v[j]-v[j-1]))
               {
                   flag=0;
                   break;
               }
        }
        if(flag)
            printf("Funny\n");
        else
            printf("Not Funny\n");
    }
    return 0;
}