In this challenge, you will determine whether a string is funny or not. To determine whether a string is funny, create a copy of the string in reverse e.g. . Iterating through each string, compare the absolute difference in the ascii values of the characters at positions 0 and 1, 1 and 2 and so on to the end. If the list of absolute differences is the same for both strings, they are funny.
Note: The absolute value of , is written as .
Input Format
The first line contains an integer , (the number of test cases).
The next lines contain a string, .
Constraints
Output Format
For each string print whether it is or on a new line.
Sample Input
2
acxz
bcxz
Sample Output
Funny
Not Funny
Explanation
You can use to store the reverse of .
Test Case 0:
s r
|c-a| = 2 = |x-z|
|x-c| = 21 = |c-x|
|z-x| = 2 = |a-c|
Each comparison is equal so we print .
Test Case 1:
s r
|c-b| = 1 != |x-z| = 2
At this point, we stop evaluating and print .
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static string funnyString(string s){
// Complete this function
if (s.Length >= 2 && s.Length <= 10000)
{
s = s.ToLower();
string R = string.Join(“”, s.Reverse().ToArray());
for (int i = 1; i < s.Length; i++)
{
int x = Math.Abs((int)s[i] – (int)s[i – 1]);
int y = Math.Abs((int)R[i] – (int)R[i – 1]);
if (x != y)
return “Not Funny”;
}
}
return “Funny”;
}
static void Main(String[] args) {
int q = Convert.ToInt32(Console.ReadLine());
for(int a0 = 0; a0 < q; a0++){
string s = Console.ReadLine();
string result = funnyString(s);
Console.WriteLine(result);
}
}
}