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[];
bool j;
int cnt,ans1,ans2,n;
int main(){
cin>>n;
scanf("%s",s+);
j = false;
cnt = ;
for(int i = ;i <= n;i++){
if(s[i] == '_' || s[i] == '(' || s[i] == ')'){
if(cnt){
if(!j)ans1 = max(cnt,ans1);
cnt = ;
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 = ;
if(j) ans2++;
}
cout<<ans1<<" "<<ans2;
return ;
}

cf723b Text Document Analysis的更多相关文章

  1. Codefoces 723B Text Document Analysis

    B. Text Document Analysis time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  2. Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟

    B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...

  3. codeforces 723B:Text Document Analysis

    Description Modern text editors usually show some information regarding the document being edited. F ...

  4. Text Document Analysis CodeForces - 723B

    Modern text editors usually show some information regarding the document being edited. For example, ...

  5. 【44.10%】【codeforces 723B】Text Document Analysis

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【Codeforces 723B】Text Document Analysis 模拟

    求括号外最长单词长度,和括号里单词个数. 有限状态自动机处理一下. http://codeforces.com/problemset/problem/723/B Examples input 37_H ...

  7. codeforces 723B Text Document Analysis(字符串模拟,)

    题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...

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

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

  9. Codeforces Round #375 (Div. 2)

    A. The New Year: Meeting Friends 水 #include <set> #include <map> #include <stack> ...

随机推荐

  1. 【java开发】面向对象初步认识与基础概念讲解

    简单的把前面的java基础知识讲了,接下来就开始面向对象的旅程了. 对象(Object):简而言之,世界是由对象组成的,一切可见的事物吧 类(class):说白了就是把具有相同的一些特征或是属性归为一 ...

  2. Postgresql 数据库维护

    删除数据库 sudo -u postgres dropdb $DB_NAME 创建数据库 sudo -u postgres psql CREATE DATABASE $DB_NAME WITH ENC ...

  3. Azure HDInsight 和 Spark 大数据实战(一)

    What is HDInsight? Microsoft Azure HDInsight 是基于 Hortonoworks Data Platform (HDP) 的 Hadoop 集群,包括Stor ...

  4. 【2016-10-21】【坚持学习】【Day11】【.net 自带的三种委托】

    三种自带委托: Action Predicate Func Action: 无返回类型 Predicate 返回类型是bool类型 Func 自定义返回类型 Action:没有参数没有返回值 Acti ...

  5. 线程同步之 yield() wait()

    yield()没有参数. sleep 方法使当前运行中的线程睡眼一段时间,进入不可运行状态,这段时间的长短是由程序设定的,yield 方法使当前线程让出CPU占有权,但让出的时间是不可设定的.yiel ...

  6. 一分钟搞定AlloyTouch图片轮播

      一分钟搞定AlloyTouch图片轮播 轮播图也涉及到触摸和触摸反馈,同时,AlloyTouch可以把惯性运动打开或者关闭,并且设置min和max为运动区域,超出会自动回弹.除了一般的竖向滚动,A ...

  7. HTML 学习笔记 JavaScript(创建对象)

    原博地址:http://www.cnblogs.com/dolphinX/p/3288118.html JavaScript 有Date Array String等这样的内置对象,功能强大实用简单,但 ...

  8. repeater 删除确认框 传多个参数

    using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using Syst ...

  9. shell脚本仅列出当前目录下的文件及文件夹

    #!/bin/bash function ergodic(){ ` # do # "/"$file ] # then # ergodic $"/"$file # ...

  10. echarts在.Net中使用实例(二) 使用ajax动态加载数据

    通过上一篇文章可以知道和echarts参考手册可知,series字段就是用来存储我们显示的数据,所以我们只需要用ajax来获取series的值就可以. option 名称 描述 {color}back ...