蓝桥杯2020年第十一届Python省赛第二题-寻找2020
2022/1/2 11:07:49
本文主要是介绍蓝桥杯2020年第十一届Python省赛第二题-寻找2020,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Code
#include<iostream> using namespace std; #define MAX_SIZE 10005 char map[MAX_SIZE][MAX_SIZE]; int main() { int ans = 0; FILE *fp = fopen("2020.txt","r"); int n=0; int m=0; if(!fp){ printf("open file fail!\n"); exit(1); } int cur; while(!feof(fp)){ cur = fgetc(fp); if(cur=='\n'){ n++; m=0; continue; } map[n][m++]=cur; } n++; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ int nx = i+3; int ny = j+3; if(map[i][j]!='2') continue; if(ny<m && map[i][j+1]=='0' && map[i][j+2]=='2' && map[i][j+3]=='0' ) // 横向 ans++; if(nx<n && map[i+1][j]=='0' && map[i+2][j]=='2' && map[i+3][j]=='0' ) // 竖向 ans++; if(nx<n && ny<m && map[i+1][j+1]=='0' && map[i+2][j+2]=='2' && map[i+3][j+3]=='0' ) // 斜向 ans++; } } cout<<ans; return 0; }
Answer
16520
这篇关于蓝桥杯2020年第十一届Python省赛第二题-寻找2020的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python