码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 688A Opponents (水题)

时间:2016-07-06 01:53:13      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

题意:给定 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;
}

 

CodeForces 688A Opponents (水题)

标签:

原文地址:http://www.cnblogs.com/dwtfukgv/p/5645474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!