10772 - The number of occurrences
raw download clone
C
views 22
,
size 903 b
#include <stdio.h>
#include <string.h>

int max(int a, int b);

int main(void)
{
    int a[4], b[9];
    int n, la = -1, lb, t, ans = 0;
    char c;

    while((c = getchar()) != '\n')
    {
        la++;
        a[la] = c - '0';
    }
    scanf("%d", &n);
    c = getchar();
    for(int i=1; i<=n; i++)
    {
        lb = -1;
        t = 0;
        while((c = getchar()) != '\n')
        {
            lb++;
            b[lb] = c - '0';
        }
        for(int j=0; j<=lb-la; j++)
        {
            for(int k=0; k<=la; k++)
            {
                if(a[k] != b[j + k])
                    break;
                else if(k == la)
                    t++;
            }
        }
        ans = max(ans, t);
    }
    printf("%d", ans);

    return 0;

}

int max(int a, int b)
{
    if(a > b)
        return a;
    else
        return b;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.