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

题目大意:

  输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括)、 下划线'_' 、括号'(' ')' 组成。【括号不会嵌套】

  求括号外面的连续字符串最大的字符串长度和括号内的连续字符串的个数。

举例:

input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
output
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(字符串模拟,)的更多相关文章

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

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

  2. Codefoces 723B Text Document Analysis

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

  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 模拟

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

  5. codeforces 723B:Text Document Analysis

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

  6. Text Document Analysis CodeForces - 723B

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

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

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

  8. Codeforces Round #528-A. Right-Left Cipher(字符串模拟)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. cf723b Text Document Analysis

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

随机推荐

  1. 使用jsp/servlet简单实现文件上传与下载

    使用JSP/Servlet简单实现文件上传与下载    通过学习黑马jsp教学视频,我学会了使用jsp与servlet简单地实现web的文件的上传与下载,首先感谢黑马.好了,下面来简单了解如何通过使用 ...

  2. jQuery自定义插件

    jQuery自定义插件 jQuery自定义插件按照功能分类,可以分为三类, 1>封装对象方法的插件,(也就是基于某个DOM元素的jQuery对象,局部的) 2>封装全局函数的插件,   ( ...

  3. SpringMVC自定义视图 Excel视图和PDF视图

    一.自定义视图-Excel视图 1.Maven依赖 引入POI <dependency> <groupId>org.apache.poi</groupId> < ...

  4. [转]Hibernate查询对象所有字段,单个字段 ,几个字段取值的问题

    原文地址:http://www.ablanxue.com/prone_3552_1.html 1. 查询整个映射对象所有字段 Java代码 //直接from查询出来的是一个映射对象,即:查询整个映射对 ...

  5. VS 2013 未找到与约束contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService...匹配的导出[vs故障]【转】

    未找到与约束 contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService RequiredTypeIdentit ...

  6. git初体验(五)SSH的理解

    一.SSH SSH是Secure shell的缩写,即"安全外壳协议",专为远程登录会话和其他网络服务提供安全性的协议,是一项计算机上的安全协议. 传统的网络服务程序,如rsh.F ...

  7. C#-WinForm-布局-Anchor-锁定布局、Dock-填充布局、工具箱中的<容器>

    Anchor - 锁定布局,锁定控件对于其父控件或窗体的位置,保持与边框固定的距离还是居中等 Dock - 填充布局,控件是否如何进行填充 ============================== ...

  8. C#-ade.net-实体类、数据访问类

    实体类.数据访问类 是由封装演变而来,使对数据的访问更便捷,使用时只需要调用即可,无需再次编写代码 实体类是按照数据库表的结构封装起来的一个类 首先,新建文件夹 App_Code ,用于存放数据库类等 ...

  9. SQL Server 自增字段重置

    --- 删除原表数据,并重置自增列 truncate table tablename --truncate方式也可以重置自增字段 --重置表的自增字段,保留数据 DBCC CHECKIDENT (ta ...

  10. Quality Trimming Via Trimmomatic

    已经去除接头(adapter) java -jar trimmomatic.jar PE -threads 20 -phred33 \ left.fastq.gz right.fastq.gz \ l ...