Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.
(Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. |x| denotes the absolute value of an integer x)
Input Format
First line of the input will contain an integer T. T testcases follow. Each of the next T lines contains one string S.
Constraints
1<=T<=10
1<=length of S<=10000
Output Format
For each string, print Funny or Not Funny in separate lines.
Sample Input
2
acxz
bcxz
Sample Output
Funny
Not Funny
Explanation
Consider the 1st testcase acxz
here
|c-a| = |x-z| = 2
|x-c| = |c-x| = 21
|z-x| = |a-c| = 2
Hence Funny.
Consider the 2st testcase bcxz
here
|c-b| != |x-z|
Hence Not Funny.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int T,i,j,flag=0;
char s[10000];
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
i=0;j=strlen(s) -1;
flag = 0;
for(;i<=j;)
{
if(abs(s[i]-s[i+1]) != abs(s[j]-s[j-1]))
{
flag = 1;
break;
}
i+=2;j-=2;
}
if(flag==1)
printf("Not Funny\n");
else
printf("Funny\n");
}
return 0;
}
Compile & Run : https://ideone.com/des1IH