Time spent here:

Monday, 14 December 2015

Problem Statement
Suppose you have a string S that has the length N. It is indexed from 0 to N1. String R is the reverse of string S. The string S is funny if the condition |SiSi1|=|RiRi1| is true for every i from 1 to N1.
Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. Here, |x| denotes the absolute value of an integer x.
Input Format
The first line of input will contain an integer T, the number of test cases. Each of the next T lines contains one string S.
Constraints
  • 1<=T<=10
  • 2<=length of S<=10000
Output Format
For each string, print Funny or Not Funny on separate lines.
Sample Input
2
acxz
bcxz
Sample Output
Funny
Not Funny
solution: 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    char a[10000];int i,j,flag=0;
    int t;
    scanf("%d",&t);
    while(t--){
    scanf("%s",a);
    //printf("%s",a);
    int n=strlen(a);
    j=n-1;
    for(i=0;i<n-1;i++)
    {
       if(abs(a[i]-a[i+1])==abs(a[j]-a[j-1]))
       {flag=1;j--;}
       else
           {flag=0;break;}
    }   
    if(flag==1)
        printf("Funny\n");
     else
         printf("Not Funny\n");
    
    }
     
    return 0;
}

1 comment: