题意:给定 n 行数,让你找出连续最多的全是1的个数。
析:好像也没什么可说的,那就判断一下,并不断更新最大值呗。
代码如下:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
typedef long long LL;
string s;
int main(){
int n, d, cnt = 0;
bool ok = false;
int m = -1;
scanf("%d %d", &n, &d);
for(int i = 0; i < d; ++i){
cin >> s;
int j;
for(j = 0; j < n; ++j)
if(s[j] != '1') break;
if(ok && j != n) ++cnt;
else if(j != n){ ok = true; cnt = 1; }
else{ cnt = 0; ok = false; }
m = max(m ,cnt);
}
printf("%d\n", m);
return 0;
}
浙公网安备 33010602011771号