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 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.

 
 
正解:模拟
解题报告:
  直接模拟,注意处理字符串的计数器的诸多情况,有一点细节。
 
 
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int inf = (<<);
int n,ans,ans2,cnt2;
char ch[]; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void work(){
n=getint(); scanf("%s",ch); int now,cnt;
for(int i=;i<n;i++) {
if(ch[i]=='(') {
ans=max(ans,cnt2); cnt2=;
now=i+; cnt=;
while(ch[now]!=')') {
if(ch[now]=='_') {
if(cnt!=) ans2++;
cnt=;
}
else cnt++;
now++;
}
if(cnt!=) cnt=,ans2++;
i=now;
}
else{
if(ch[i]=='_') {
if(cnt2!=) ans=max(cnt2,ans);
cnt2=;
}
else cnt2++;
}
}
if(cnt2!=) ans=max(ans,cnt2);
printf("%d %d",ans,ans2);
} int main()
{
work();
return ;
}

codeforces 723B:Text Document Analysis的更多相关文章

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

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

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

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

  3. Codefoces 723B Text Document Analysis

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

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

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

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

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

  6. Text Document Analysis CodeForces - 723B

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

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

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

  8. cf723b Text Document Analysis

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

  9. JavaScript -- 时光流逝(十一):DOM -- Document 对象

    JavaScript -- 知识点回顾篇(十一):DOM -- Document 对象 (1) document.activeElement: 返回文档中当前获得焦点的元素. <!doctype ...

随机推荐

  1. 返回标量CLR自定义函数

    昨天有学习了返回表自定义函数<CLR Table-Valued函数>http://www.cnblogs.com/insus/p/4378354.html.今天学习另一个,实现返回标量(S ...

  2. C++ 中dynamic_cast&lt;&gt;的使用方法小结 -判断类型-rtti

    将一个基类对象指针(或引用)cast到继承类指针,dynamic_cast会根据基类指针是否真正指向继承类指针来做相应处理          即会作一定的判断.        对指针进行dynamic ...

  3. Vue系列:如何将百度地图包装成Vue的组件

    主要分解为如下步骤: (1)在html文件中引入百度地图, <script type="text/javascript" src="http://api.map.b ...

  4. 读懂IL代码就这么简单(三)完结篇

    一 前言 写了两篇关于IL指令相关的文章,分别把值类型与引用类型在 堆与栈上的操作区别详细的写了一遍 这第三篇也是最后一篇,之所以到第三篇就结束了,是因为以我现在的层次,能理解到的都写完了,而且个人认 ...

  5. ASP.NET文件上传大小的限制解决方案

    我们大家都知道ASP.NET为我们提供了文件上传服务器控件FileUpload,默认情况下可上传的最大文件为4M,如果要改变可上传文件大小限制,那么我们可以在web.config中的httpRunti ...

  6. HTML5+JS 《五子飞》游戏实现(八)人机对战

    要想实现人机对战,就必须让电脑自动下棋,而且要知道自动去查找对方的棋子,看看有没有可以挑一对的,有没有可以夹一个的,这样下起来才有意思. 当电脑用户下完棋后,电脑应立即搜索用户的棋子,然后如果没有被吃 ...

  7. ModernUI教程:MEF应用向导

    本文主要说明在Modern UI框架下使用MEF的必要步骤,关于MEF请自行脑补. MEF-INTO-MUI实例代码下载: MefMuiApp.zip 1:创建一个导出属性 ModernFrame用来 ...

  8. MATLAB中subplot的用法

    写成subplot(m,n,p)或者subplot(mnp). subplot是将多个图画到一个平面上的工具.其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一行的, ...

  9. SQL复杂查询和视图(2)

    分组查询 SQL可以将检索到的元组按某一条件进行分组,分组是属性值相同的为一组 求每个学生的平均成绩 SELECT sn,AVG(score)FROM scGROUP BY sn 先按sn进行分组,即 ...

  10. BroadcoastReceiver之短信到来监听和获取内容

    废话就不说了,新建类继承,然后配置Manifest.xml:如下 <!--需要给一个接收短信的权限 --> <uses-permission android:name="a ...