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

Codeforces_723_B

时间:2016-10-04 01:23:49      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

http://codeforces.com/problemset/problem/723/B

 

求括号内单词数和括号外最大单词长度,注意细心,尤其是ok和sum的置0。

 

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;

int main()
{
    int n;
    char s[300];
    scanf("%d",&n);
    getchar();
    gets(s);
    int maxx = 0,cnt = 0,flag = 0,ok = 0,sum = 0;
    for(int i = 0;i < n;i++)
    {
        if(s[i] == ()
        {
            flag = 1;
            ok = 0;
        }
        else if(s[i] == ))
        {
            sum = 0;
            flag = 0;
            if(ok)    cnt++;
        }
        else if(flag == 0)
        {
            if(s[i] == _)    sum = 0;
            else
            {
                sum++;
                maxx = max(sum,maxx);
            }
        }
        else if(flag == 1)
        {
            if(s[i] == _)
            {
                if(ok)    cnt++;
                ok = 0;
            }
            else    ok = 1;
        }
    }
    printf("%d %d\n",maxx,cnt);
    return 0;
 } 

 

Codeforces_723_B

标签:

原文地址:http://www.cnblogs.com/zhurb/p/5929933.html

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