11621 - pE - Exquisite Substrings
raw download clone
C
views 20
,
size 829 b
#include <stdio.h>

int main(void)
{
    char c;
    char s[2001];
    int n, mid, ans;

    c = getchar();
    while(c != EOF)
    {
        n = 0;
        ans = 0;
        while(c != '\n')
        {
            n++;
            s[n] = c;
            c = getchar();
        }
        for(int i=2; i<=n-1; i++)
        {
            for(int j=1; i-j>=1, i+j<=n; j++)
            {
                if(s[i-j] != s[i+j])
                    break;
                ans++;
            }
        }
        for(int i=1; i<=n-1; i++)
        {
            for(int j=0; i-j>=1, i+j+1<=n; j++)
            {
                if(s[i-j] != s[i+j+1])
                    break;
                ans++;
            }
        }
        printf("%d\n", ans);
        c = getchar();
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.