Tuesday, 25 July 2017

Funny strings



Suppose you have a String, , of length that is indexed from to . You also have some String, , that is the reverse of String . is funny if the condition is true for every character from to .
Note: For some String , denotes the ASCII value of the -indexed character in . The absolute value of an integer, , is written as .
Input Format
The first line contains an integer, (the number of test cases).
Each line of the subsequent lines contain a string, .
Constraints
Output Format
For each String (where ), print whether it is or on a new line.
Sample Input
2
acxz
bcxz
Sample Output
Funny
Not Funny
Explanation
Test Case 0:



As each comparison is equal, we print .
Test Case 1:
, but
At this point, we stop evaluating (as ) and print .


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

char* funnyString(char* s){
    int flag = 1 ;
    char *m;
    for(int  i = 0;i<strlen(s)/2;i++)
    {
        if (abs(s[i]-s[i+1])==abs(s[strlen(s)-i-1]-s[strlen(s)-i-2]))
        {continue;}
        else
        {flag= 0;
            break;}
       
    }
   
    if (flag ==1)
    {m= "Funny";}
    else   
     {m="Not Funny";}
    return m ;
    // Complete this function
}

int main() {
    int q;
    scanf("%i", &q);
    for(int a0 = 0; a0 < q; a0++){
        char* s = (char *)malloc(512000 * sizeof(char));
        scanf("%s", s);
        int result_size;
        char* result = funnyString(s);
        printf("%s\n", result);
    }
    return 0;
}

No comments:

Post a Comment