题目链接: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. android与网络的交互

    有三种方式: 数据下载,数据上传,数据浏览 URL中一些符号 ?分隔URL和参数 &URL中参数之间的分隔符 =URL中参数对应的值

  2. JVM垃圾收集器介绍

    垃圾回收算法是GC的方法论,垃圾收集器就是内存回收的具体实现. 一.Serial 收集器 单线程收集器,在进行GC时,必须暂停所有的工作线程(Stop The World),直到GC收集结束. 缺点: ...

  3. ASP.NET杂谈-一切都从web.config说起(2)(ConfigSections详解-上 )

    ConfigSections的结构 首先我们先回顾一下ConfigSections的结构和它子节点的说明,如下: 1: <configSections> 2: <sectionGro ...

  4. asp.net捕获全局未处理异常的几种方法

    通过HttpModule来捕获未处理的异常[推荐] 首先需要定义一个HttpModule,并监听未处理异常,代码如下: public void Init(HttpApplication context ...

  5. ActiveMQ(七)_伪集群和主从高可用使用

      一.本文目的         介绍如何在同一台虚拟机上搭建高可用的Activemq服务,集群数量包含3个Activemq,当Activemq可用数>=2时,整个集群可用.         本 ...

  6. 2010-2014总结 ____V_V____ hello-world

    .caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table ...

  7. 唯一分解定理 poj 1365

    一行代表一个数 x 给你底数和指数 求x-1的唯一分解定理的底数和指数 从大到小输出 #include<stdio.h> #include<string.h> #include ...

  8. EasyIcon:免费图标搜索和下载平台

    EasyIcon是一个为设计师提供免费图标搜索和下载服务的网站. 步骤如下: 第一步,打开EasyIcon网站主页: http://www.easyicon.net/ 第二步,在EasyIcon网站的 ...

  9. java-读取类中的属性名称和值

    方法 /** * 获取类中的所有属性明名称和值(因涉及到可能会是继承关系的父类,所以从f中去属性名称,从f2中取值,两个可以一样,也可以使父类) * @param f:读取属性类(如果取父类的,则这里 ...

  10. 【POJ 1269】判断两直线相交

    题 利用叉积解方程 #include <cstdio> #define MAX 1<<31 #define dd double int xmult(dd x1,dd y1,dd ...