标签:
求括号外最长单词长度,和括号里单词个数。
有限状态自动机处理一下。
http://codeforces.com/problemset/problem/723/B
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
5 4
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
2 6
27
(LoooonG)__shOrt__(LoooonG)
5 2
5
(___)
0 0
#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);
printf("%d %d",ans1,ans2);
}#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);
}
【Codeforces 723B】Text Document Analysis 模拟
标签:
原文地址:http://www.cnblogs.com/flipped/p/5929991.html