Untitled
raw download clone
C
views 30
,
size 809 b
#include <stdio.h>
#include <string.h>

char str[2005];
char sub[2005];
int len;
int count;
void reverse(int num);

int main(void)
{
    while (scanf("%s", str) != EOF)
    {
        len = strlen(str);
        strcpy(sub, str);
        reverse(2);
        count = 0;
    }
    return 0;
}


void reverse(int num)
{
    if (num > len)
    {
        printf("%d\n", count);
        return;
    }
    char temp;
    //printf("  %d  ", num);
    for (int i = 0;i <= len - num;i++)
    {
        for (int j = 0;j < num / 2;j++)
        {
            temp = sub[i + j];
            sub[i + j] = sub[i + num - 1 - j];
            sub[i + num - 1 - j] = temp;
        }
        if (strcmp(str, sub) == 0) count++;
        strcpy(sub, str);
    }

    reverse(num + 1);
}
close fullscreen
Login or Register to edit or fork this paste. It's free.