• + 0 comments

    My C code

    bool isTheSameArrayOfInt(const int* r,const int* t,const int size) {
        for(int i = 0;i < size;i++) {
            if(r[i] != t[i]) {
                return false;
            }
        }
        return true;
    }
     
    char* funnyString(char* s) {
        int e = strlen(s) - 1, count = 0, taille = strlen(s);;
        int *begin = (int*)malloc((strlen(s))*sizeof(int));
        int *end = (int*)malloc((strlen(s))*sizeof(int));
        if(begin == NULL || end == NULL) {
            perror("allocation failed\n");
            exit(EXIT_FAILURE);
        }
        for(int i = 1;i < taille;i++) {
            begin[count] = abs(s[i] - s[i - 1]);
            end[count] = abs(s[e] - s[e - 1]);
            e--;
            count++;
        }
    
        bool result = isTheSameArrayOfInt(begin,end,count);
    
        free(begin);
        free(end);
    
        return result ? "Funny" : "Not Funny";
    }