CodeForces 688A Opponents (水题)

题意:给定 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
", m);
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5645474.html