求括号外最长单词长度,和括号里单词个数。
有限状态自动机处理一下。
http://codeforces.com/problemset/problem/723/B
Examples
input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
output
5 4
input
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
output
2 6
input
27
(LoooonG)__shOrt__(LoooonG)
output
5 2
input
5
(___)
output
0 0
#include<bits/stdc++.h>
using namespace std;
int a,f,k;
char s[];
int ans1,ans2;
int main(){
scanf("%d %s",&a,s);
for(int i=;s[i];i++){ if(f==){
if(s[i]=='('){
f=;
ans1=max(ans1,k);
k=;
}else if(s[i]=='_'){
ans1=max(ans1,k);
k=;
}else{
k++;
}
}else if(f==){
if(s[i]==')'){
f=;
}else if(s[i]=='_'){ }else if(s[i]<='Z'&&s[i]>='A'||s[i]<='z'&&s[i]>='a'){
f=;
ans2++;
}
}else if(f==){
if(s[i]==')'){
f=;
}else if(s[i]=='_'){
f=;
}
}
}
ans1=max(ans1,k);//wa了一次因为没有计算到最后一个单词。
printf("%d %d",ans1,ans2);
}