首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【Codeforces 723B】Text Document Analysis 模拟

【Codeforces 723B】Text Document Analysis 模拟

作者头像
饶文津
发布2020-06-02 10:58:21
发布2020-06-02 10:58:21
3700
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏

求括号外最长单词长度,和括号里单词个数。

有限状态自动机处理一下。

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

Examples

input

代码语言:javascript
复制
37
_Hello_Vasya(and_Petya)__bye_(and_OK)

output

代码语言:javascript
复制
5 4

input

代码语言:javascript
复制
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__

output

代码语言:javascript
复制
2 6

input

代码语言:javascript
复制
27
(LoooonG)__shOrt__(LoooonG)

output

代码语言:javascript
复制
5 2

input

代码语言:javascript
复制
5
(___)

output

代码语言:javascript
复制
0 0
代码语言:javascript
复制
#include<bits/stdc++.h>
using namespace std;
int a,f,k;
char s[300];
int ans1,ans2;
int main(){
    scanf("%d %s",&a,s);
    for(int i=0;s[i];i++){

        if(f==0){
            if(s[i]=='('){
                f=1;
                ans1=max(ans1,k);
                k=0;
            }else if(s[i]=='_'){
                ans1=max(ans1,k);
                k=0;
            }else{
                k++;    
            }
        }else if(f==1){
            if(s[i]==')'){
                f=0;    
            }else if(s[i]=='_'){
                
            }else if(s[i]<='Z'&&s[i]>='A'||s[i]<='z'&&s[i]>='a'){
                f=3;
                ans2++;
            }
        }else if(f==3){
            if(s[i]==')'){
                f=0;
            }else if(s[i]=='_'){
                f=1;
            }
        }
    }
    ans1=max(ans1,k);//wa了一次因为没有计算到最后一个单词。
    printf("%d %d",ans1,ans2);
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-10-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档