#include <stdio.h>
#include <string.h>
char text[500][500];
void copytext()
{ //将文本内容复制到数组text中
    char c[500];
    int line = 0;
    FILE *fp = fopen("find2020.txt", "r");
    if (fp == NULL)
    {
        printf("failed to open file!\n");
    }
    else
    {
        while (fgets(c, 500, fp))
            strcpy(text[line++], c);
    }
    fclose(fp);
}
int main()
{
    int i, j = 0, count = 0;
    copytext(); //将文本内容复制到数组text中
                //求每行的2020
    for (i = 0; i < 500; i++)
        for (j = 0; j < 500; j++)
            if (text[i][j + 3] != NULL)
            {
                if (text[i][j] == '2' && text[i][j + 1] == '0' && text[i][j + 2] == '2' && text[i][j + 3] == '0')
                {
                    count++;
                    j = j + 1;
                }
            }
            else
            {
                break;
            }
    //求每列的2020
    for (j = 0; j < 500; j++)
        for (i = 0; i < 500; i++)
            if (text[i + 3][j] != NULL)
            {
                if (text[i][j] == '2' && text[i + 1][j] == '0' && text[i + 2][j] == '2' && text[i + 3][j] == '0')
                {
                    count++;
                    i = i + 1;
                }
            }
            else
            {
                break;
            }
    //求对角线的2020
    for (i = 0; i < 500; i++)
        for (j = 0; j < 500; j++)
            if (text[i + 3][j + 3] != NULL)
            {
                if (text[i][j] == '2' && text[i + 1][j + 1] == '0' && text[i + 2][j + 2] == '2' && text[i + 3][j + 3] == '0')
                    count++;
            }
            else
            {
                break;
            }
    printf("%d\n", count);

    return 0;
}
