Text Document Analysis CodeForces - 723B
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).
Example
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
5 4
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
2 6
27
(LoooonG)__shOrt__(LoooonG)
5 2
5
(___)
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<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cctype>
using namespace std; int main() {
int n;
char a[];
while(scanf("%d%s",&n,a)!=EOF){
int sum=,maxn=,len=,flag=;
for (int i= ;i<n ;i++){
if (a[i]=='(') flag=;
if (a[i]==')') flag=;
if (isalpha(a[i])) len++;
else len=;
if (flag==) maxn=max(maxn,len);
else if (len==) sum++;
}
printf("%d %d\n",maxn,sum);
}
return ;
}
Text Document Analysis CodeForces - 723B的更多相关文章
- Codefoces 723B Text Document Analysis
B. Text Document Analysis time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟
B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...
- codeforces 723B:Text Document Analysis
Description Modern text editors usually show some information regarding the document being edited. F ...
- 【44.10%】【codeforces 723B】Text Document Analysis
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 723B】Text Document Analysis 模拟
求括号外最长单词长度,和括号里单词个数. 有限状态自动机处理一下. http://codeforces.com/problemset/problem/723/B Examples input 37_H ...
- codeforces 723B Text Document Analysis(字符串模拟,)
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...
- CodeForces 723B Text Document Analysis (水题模拟)
题意:给定一行字符串,让你统计在括号外最长的单词和在括号内的单词数. 析:直接模拟,注意一下在左右括号的时候有没有单词.碰到下划线或者括号表示单词结束了. 代码如下: #pragma comment( ...
- cf723b Text Document Analysis
Modern text editors usually show some information regarding the document being edited. For example, ...
- 【Codeforces】Round #375 (Div. 2)
Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...
随机推荐
- P1045 麦森数
别问我为什么要写水题 #include <iostream> #include <cstdio> #include <cstring> #include <a ...
- 初识RESTful
前言:两个月没写博客了,我真是太贱了哈哈.先简单说下我这两个月做了啥吧.8月26号从BIGO离职,回学校准备秋招.9月初时才发现已经错过秋招内推时间,其实秋招内推拿offer是有较大概率的.9月才开始 ...
- redis requires ruby version 2.2.2的解决方案
在执行gem install redis时 提示: gem install redis ERROR: Error installing redis: redis requires Ruby versi ...
- 将你的Python Web程序部署到Ubuntu服务器上
在本文记录了我在Ubuntu中部署Flask Web站点的过程, 其中包括用户创建.代码获取.Python3环境的安装.虚拟环境设置.uWSGI启动程序设置,并将Nginx作为前端反向代理.希望对各位 ...
- python学习:使用正则收集ip信息
使用正则表达式收集主机信息 #!/usr/bin/env python from subprocess import Popen, PIPE import re def ge ...
- Windows 系统下安装 dig 命令
dig是一个Linux下用来DNS查询信息的小工具,dig全称是Domain Information Groper,与nslookup类似,但比nslookup功能更强大.Windows只有nsloo ...
- Chrome Stylist 插件 (CSS备份)
Stylist 插件还是很好用的,可以给网站自定义CSS样式,(还有个插件叫"油猴子",可以给网页加载自定义JS): 不过麻烦的是,现在的最新版360浏览器不能显示这个插件(这个浏 ...
- vue 路由懒加载 使用,优化对比
vue这种单页面应用,如果没有应用懒加载,运用webpack打包后的文件将会异常的大,造成进入首页时,需要加载的内容过多,时间过长,会出啊先长时间的白屏,即使做了loading也是不利于用户体验,而运 ...
- 原生Java代码拷贝目录
拷贝.移动文件(夹),有三方包commons-io可以用,但是有时候有自己的需求,只能使用原生java代码,这时可以用以下几种方式进行拷贝: 1.使用系统命令(Linux)调用 此种方式对操作系统有要 ...
- 解决windows10和ubuntu16.04双系统下时间不对的问题
电脑安装完windows10与ubuntu16.04双系统后,Ubuntu的时间总会和Windows的时间相差8小时,原因在于windows认为BIOS时间是本地时间,Ubuntu认为BIOS时间是U ...