Codefoces 723B Text Document Analysis
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 %dn", s1,s2);
24 }
25 return 0;
26 }
- Android中Fragment+ViewPager的配合使用
- 结合机器学习与生物医学技术,寻找Uber司机出行模式
- ASP.NET MVC 4 - 测试驱动 ASP.NET MVC
- LVS+Keepalived高可用环境部署梳理(主主和主从模式)
- 随着区块链的火爆,相关顶级域名“矿池”KC.com已建站
- Flash/Flex学习笔记(50):3D线条与填充
- LVM常规操作记录梳理(扩容/缩容/快照等)
- Flash/Flex学习笔记(55):背面剔除与 3D 灯光
- 资源等待类型sys.dm_os_wait_stats
- NVIDIA不再允许数据中心用GeForce驱动,提供区块链服务除外
- 非常强悍并实用的双机热备+负载均衡线上方案
- Apache 压力测试工具ab
- SQL之收集SQL Server线程等待信息
- 聚合索引(clustered index) / 非聚合索引(nonclustered index)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 机器学习-文本分类(2)-新闻文本分类
- Mysql5.6版本新增列,执行DDL的时候竟然锁表了,这应该是是最好的解决办法之一了!!
- spring之bean的作用域
- spring之spring表达式语言:SpEL
- 反欺诈模型(数据不平衡)
- 基于TypeScript封装Axios笔记(一)
- 一次性清除“知乎”所有DIV
- spring之bean之间的关系
- spring之未加后置处理器的bean的生命周期
- linux之在centos7中配置java开发环境
- 秒懂java规则表达式框架Aviator2.3.0
- 细品Redis高性能数据结构之SDS
- linux之第一个shell程序
- pyspark之从HDFS上读取文件、从本地读取文件
- spring之使用外部属性文件(连接数据库时使用)