codeforces 723B Text Document Analysis(字符串模拟,)
题目链接:http://codeforces.com/problemset/problem/723/B
题目大意:
输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括)、 下划线'_' 、括号'(' ')' 组成。【括号不会嵌套】
求括号外面的连续字符串最大的字符串长度和括号内的连续字符串的个数。
举例:
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
5 4
括号外面的连续的字符串最长的字符串长度为 5 括号内有 4 个连续的字符串。
解题思路:
模拟扫描一遍即可,分为两种情况
1.括号外面的字符串,如果碰到英文字符,则while 循环即可直到不是英文字母,在循环的同时用一个tem记录字符串的长度,找到一个最长的即可。
2.括号里面,如果碰到‘(’ 则进入循环,碰到‘)’退出,在该循环内,如果是英文字母,则统计个数cut++,同时while循环,直到不是英文字母。
以上循环是注意数组尾,简单提一下,自己再写时加了判断,1A.
AC Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
char na[];
while(scanf("%d",&n)!=EOF)
{
int maxn=,cut=;
cin>>na;
for(int i=; i<strlen(na); i++)
{
if(na[i]=='_')continue;
if(isalpha(na[i]))
{
int tem=;
while(isalpha(na[i])&&i<strlen(na))
tem++,i++;
maxn=max(maxn,tem);
}
if(na[i]=='(')
{
i+=;//.
while(na[i]!=')'&&i<strlen(na))
{
if(na[i]=='_')
{
i++;
continue;
}
if(isalpha(na[i]))
{
cut++;
while(isalpha(na[i])&&i<strlen(na))i++;
}
}
}
}
printf("%d %d\n",maxn,cut);
}
return ;
}
codeforces 723B Text Document Analysis(字符串模拟,)的更多相关文章
- CodeForces 723B Text Document Analysis (水题模拟)
题意:给定一行字符串,让你统计在括号外最长的单词和在括号内的单词数. 析:直接模拟,注意一下在左右括号的时候有没有单词.碰到下划线或者括号表示单词结束了. 代码如下: #pragma comment( ...
- 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 模拟
求括号外最长单词长度,和括号里单词个数. 有限状态自动机处理一下. http://codeforces.com/problemset/problem/723/B Examples input 37_H ...
- codeforces 723B:Text Document Analysis
Description Modern text editors usually show some information regarding the document being edited. F ...
- Text Document Analysis CodeForces - 723B
Modern text editors usually show some information regarding the document being edited. For example, ...
- 【44.10%】【codeforces 723B】Text Document Analysis
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #528-A. Right-Left Cipher(字符串模拟)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- cf723b Text Document Analysis
Modern text editors usually show some information regarding the document being edited. For example, ...
随机推荐
- “CEPH浅析”系列之八——小结
最初决定写这些文章的时候,本打算大致记录一下,几千字也就了事了.可是越写越觉得东西多,不说明白总有些不甘心,于是就越写越长,到这儿为止貌似已经有一万七千多字了.除了博士论文之外,应该是没有写过更长的东 ...
- DOCTYPE是什么鬼?文档模式又是什么鬼?
!DOCTYPE !DOCTYPE是什么: 在所有 HTML 文档中规定 DOCTYPE 是非常重要的,这样浏览器就能了解预期的文档类型, 告诉浏览器要通过哪一种规范(文档类型定义 DTD)解析文档( ...
- 管理系统UI: System Bar 详解
Google原文: http://developer.android.com/training/system-ui/index.html 管理系统UI之一:淡化System Bar(Dimming t ...
- 【收藏】Android更新UI的几种常见方法
----------------将会调用onDraw()重绘控件---------------- 1.view.invalidate刷新UI(主线程) 2.view.postInvalidate刷 ...
- IOS-App installation failed原因及解决方法
在用真机调试的时候,每次运行app都会弹出这个框,点击ok后,再次运行就没问题了.刚开始觉得没什么,无非就是多点几次,到后来,觉得这也很浪费时间,严重影响开发效率,在网上搜索了一遍后,决定将解决方案写 ...
- bootstrap 双层模态框的实现
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- java.io.IOException: No FileSystem for scheme: hdfs
在这篇文章中,介绍了如何将Maven依赖的包一起打包进jar包.使用maven-assembly打成jar后,将这个jar提供给其他工程引用的时候,报出如下错误: log4j:WARN No appe ...
- Python 循环判断和数据类型
循环和判断 1.if 形式 if condition_1: statement_block_1 elif condition_2: statement_block_2 else: statement_ ...
- [资料搜集狂]D3.js数据可视化开发库
偶然看到一个强大的D3.js,存档之. D3.js 是近年来十分流行的一个数据可视化开发库. 采用BSD协议 源码:https://github.com/mbostock/d3 官网:http://d ...
- windows下安装使用Composer记录
一直以来都是直接下载类库文件放到项目中使用 Composer是一个PHP依赖管理工具,有了它,就可以对依赖的包进行统一管理,而且在项目中可以实现自动加载 安装和使用composer 下载并且运行 Co ...