#include<bits/stdc++.h>
using namespace std;
char text[500][500];
void copytext(){//将文本内容复制到数组text中
char c[500];
int line = 0;
FILE *fp = fopen("2020.txt","r");
if (fp==NULL)
{
printf("failed to open file!\n");
}
else
{
while(fgets(c,500,fp))
strcpy(text[line++],c);
}
fclose(fp);
}
void copy2020()
{
FILE *fp;
int i=0;
char c[500];
if( (fp=fopen("2020.txt","r"))==NULL )
{
printf("open file failed.");
return;
}
else
{
while(fgets(c,500,fp))
{
strcpy(text[i++],c);
}
}
fclose(fp);
}
void C_plus2020()
{
char c[500];
int i=0;
ifstream ifile("2020.txt");
while(ifile.good())
{
ifile.getline(c,500);
strcpy(text[i++],c);
}
}
int main()
{
int i,j=0,count=0;
C_plus2020();//将文本内容复制到数组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;
}
//#include <stdio.h>
//#include <stdlib.h>
//
//#define N 100
//int main() {
// FILE *fp;
// char str[N + 1];
//
// //判断文件是否打开失败
// if ( (fp = fopen("2020.txt", "rt")) == NULL ) {
// puts("Fail to open file!");
// exit(0);
// }
//
// //循环读取文件的每一行数据
// while( fgets(str, N, fp) != NULL ) {
// printf("%s", str);
// }
//
// //操作结束后关闭文件
// fclose(fp);
// return 0;
//}