cf723b Text Document Analysis

Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.

In this problem you should implement the similar functionality.

You are given a string which only consists of:

  • uppercase and lowercase English letters,
  • underscore symbols (they are used as separators),
  • parentheses (both opening and closing).

It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can‘t be nested.

For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".

Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds:

  • the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
  • the number of words inside the parentheses (print 0, if there is no word inside the parentheses).

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.

Output

Print two space-separated integers:

  • the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
  • the number of words inside the parentheses (print 0, if there is no word inside the parentheses).

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

Note

In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.

/*
就是让你统计括号外最长串和括号内单词数
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char cmd,s[550];
bool j;
int cnt,ans1,ans2,n;
int main(){
    cin>>n;
    scanf("%s",s+1);
    j = false;
    cnt = 0;
    for(int i = 1;i <= n;i++){
        if(s[i] == ‘_‘ || s[i] == ‘(‘ || s[i] == ‘)‘){
            if(cnt){
                if(!j)ans1 = max(cnt,ans1);
                cnt = 0;
                if(j) ans2++;
            }
        }
        if(s[i] == ‘(‘) j = true;
        if(s[i] == ‘)‘) j = false;
        if(s[i] != ‘_‘ && s[i] != ‘(‘ && s[i] != ‘)‘) cnt++;
    }
    if(cnt){
        if(!j)ans1 = max(cnt,ans1);
        cnt = 0;
        if(j) ans2++;
    }
    cout<<ans1<<" "<<ans2;
    return 0;
}
时间: 2024-10-22 22:35:58

cf723b Text Document Analysis的相关文章

codeforces 723B:Text Document Analysis

Description Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You

CodeForces 723B Text Document Analysis (水题模拟)

题意:给定一行字符串,让你统计在括号外最长的单词和在括号内的单词数. 析:直接模拟,注意一下在左右括号的时候有没有单词.碰到下划线或者括号表示单词结束了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include

【Codeforces 723B】Text Document Analysis 模拟

求括号外最长单词长度,和括号里单词个数. 有限状态自动机处理一下. 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

CodeForces 723B Text Document Analysis

模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #incl

Imaging Techniques in Document Analysis Processes(文档分析过程中的图像技术)

4. Imaging Techniques in Document Analysis Processes(文档分析过程中的图像技术) ContentsIntroduction. ....................................................................................... 74Basic Image Processing Algorithms. ....................................

Codeforces Round #375 (Div. 2) ABCDE

A - The New Year: Meeting Friends 水 #include<iostream> #include<algorithm> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<max(a,max(b,c)) - min(a,min(b,c)) <<endl; return 0; } B - Text Document A

Unsupervised Learning and Text Mining of Emotion Terms Using R

Unsupervised learning refers to data science approaches that involve learning without a prior knowledge about the classification of sample data. In Wikipedia, unsupervised learning has been described as "the task of inferring a function to describe h

awesome scene text

awesome scene text scene text recognition  scene text spotter  scene text detection Awesome Scene text IncepText: A New Inception-Text Module with Deformable PSROI Pooling for Multi-Oriented Scene Text Detection mutli-oriented text Abstract Incidenta

Handbook of Document Image Processing and Recognition文档图像处理与识别手册

编辑:David Doermann(马里兰大学)Karl Tombre(洛林大学) 前言 In the beginning, there was only OCR. After some false starts, OCR became a competitive commercial enterprise in the 1950’s. A decade later there were more than 50 manufacturers in the US alone. With the a