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

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.

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

正解:模拟
解题报告:
直接模拟,注意处理字符串的计数器的诸多情况,有一点细节。
下面给出AC代码:
 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 char s[10000];
6 int n,len=0,s1 = 0,s2 = 0;
7 bool flag = 0;
8 while(scanf("%d%s",&n,&s)!=EOF)
9 {
10 //for(int i=0;i<n;i++)
11 //scanf("%c",&s[i]);
12 for(int j = 0; j < n; j++)
13 {
14 if(s[j] == '(') flag=1;
15 if(s[j] == ')') flag=0;
16 if((s[j] >= 'a' && s[j] <= 'z') || (s[j] >= 'A' && s[j] <= 'Z')) {
17 len++;
18 }
19 else len = 0;
20 if(!flag) s1=max(s1, len);
21 else if(len==1)s2++;
22 }
23 printf("%d %d\n", s1,s2);
24 }
25 return 0;
26 }

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

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

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

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

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

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

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

  4. codeforces 723B:Text Document Analysis

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

  5. Text Document Analysis CodeForces - 723B

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

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

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

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

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

  8. cf723b Text Document Analysis

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

  9. Codeforces Round #375 (Div. 2)

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

随机推荐

  1. 随笔:JavaScript函数中的对象----arguments

    关于arguments 调用函数时,如果需要传参,其实参数就是一个数组,在函数体的内置对象arguments可以访问这个数组,如: arguments[0]:第一个参数 arguments[1]:第二 ...

  2. rsync 指定端口拷贝

    rsync -aP -e 'ssh -p 2288' ssh-audit.dat 172.18.18.31:/opt/freesvr/audit/sshgw-audit/sbin

  3. go generate 生成代码

    今后一段时间要研究下go generate,在官网博客上看了Rob Pike写的generating code,花了一些时间翻译了下.有几个句子翻译的是否正确有待考量,欢迎指正. 生成代码 通用计算的 ...

  4. tomcat 设置jvm 参数

    在catalina.bat中设置 正确的做法是设置成这样set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx256m,避免JAVA_OPTS参数覆盖

  5. mysql commit 和 rollback

    转自:http://blog.csdn.net/ying_593254979/article/details/12134629 SQL 语言类型 从功能上划分,SQL 语言可以分为DDL,DML和DC ...

  6. linux系统编程快速定位头文件的技巧之强大的grep命令

    这个技巧来自于我的实际开发碰到的: inet_addr这个函数用于把ip地址转成网络字节序,他的原型:in_addr_t inet_addr(const char *cp); 返回值为一个in_add ...

  7. unittest单元测试框架详解

    unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...

  8. J2EE 项目 org.apache.jasper.JasperException: 解决方法

    项目从一个电脑转移到另一台电脑总是有各种意外qaq~ 刚放假把从实验室的项目拷回自己的电脑回家继续coding,结果出了这个错误.... 各个地方都调试原来是Tomcat版本问题!!!我电脑上的是6. ...

  9. Wechat 微信端调用“微信支付接口”的正确方式

    微信端的项目中,比如微信商城之类的,肯定会涉及到微信支付这一块: 下面直接上详细的代码: var data = {--}; // 调用微信支付需要的数据 function onBridgeReady( ...

  10. TPFrame框架之robot模块的基本使用

    经过几天的努力,基本功能版已经完成,有待大家验证... robot插件主要的功能是帮助我们写部分代码的基本,目前阶段已经实现后台curd数据管理的基本操作,更多功能待续... 1.首先下载robot插 ...