Codeforces Round #375 (Div. 2) - B

时间:2023-03-08 23:44:37
Codeforces Round #375 (Div. 2) - B

题目链接:http://codeforces.com/contest/723/problem/B

题意:给定一个字符串。只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词。现在要你输出括号外面的单词的最大长度和括号里面出现的单词数目

思路:按照题目模拟就好了。写的比较搓。

#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<math.h>
#include<time.h>
#include<vector>
#include<iostream>
using namespace std;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const int MAXN = + ;
int n;
char str[MAXN];
int main(){
while (~scanf("%d", &n)){
scanf("%s", str);
bool inner = false; int maxlen = , cnt = ;
for (int i = ; i<strlen(str); i++){
if (str[i] == '_'){
continue;
}
if (str[i] == '('){
int k = i + ; bool haschar = false;
for (; k<strlen(str); k++){
if (str[k] == ')'){
cnt += (haschar ? : );
i = k; break;
}
if (str[k] == '_'){
cnt += (haschar ? : );
haschar = false;
}
else{
haschar = true;
}
}
}
else{
int k = i; int tmplen = ;
for (; k <= strlen(str); k++){
if (k == strlen(str)){
maxlen = max(maxlen, tmplen);
i = k;
break;
}
else if (str[k] == '_'){
maxlen = max(maxlen, tmplen);
tmplen = ;
continue;
}
else if (str[k] == '('){
maxlen = max(maxlen, tmplen);
i = k - ;
break;
}
else{
tmplen++;
}
}
}
}
printf("%d %d\n", maxlen, cnt);
}
return ;
}