题目链接: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. [转]SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)

    原文地址:http://blog.csdn.net/zhshulin/article/details/37956105#comments 使用SSM(Spring.SpringMVC和Mybatis) ...

  2. 【POJ 3693】Maximum repetition substring 重复次数最多的连续重复子串

    后缀数组的论文里的例题,论文里的题解并没有看懂,,, 求一个重复次数最多的连续重复子串,又因为要找最靠前的,所以扫的时候记录最大的重复次数为$ans$,扫完后再后从头暴力扫到尾找重复次数为$ans$的 ...

  3. 网络流 poj 2135

    n个点 m条边 给m条边 求1->n n->1 最小花费,每条边最多走一次 两个最短路显然不行 会影响另外一条 #include<stdio.h> #include<al ...

  4. Mysql-报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost

    报错:1130-host ... is not allowed to connect to this MySql server   解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在l ...

  5. 【收藏】Java多线程/并发编程大合集

    (一).[Java并发编程]并发编程大合集-兰亭风雨    [Java并发编程]实现多线程的两种方法    [Java并发编程]线程的中断    [Java并发编程]正确挂起.恢复.终止线程    [ ...

  6. c#如何使输入数据类型限制,C#如何添加限制

    验证n位的数字:^\d{n}$ ,例如要输6位数字,不能多也不能少: ^\d{6}$ 验证数字的正则表达式集 验证数字:^[0-9]*$验证n位的数字:^\d{n}$验证至少n位数字:^\d{n,}$ ...

  7. 16 IO操作文件读写

    IO的分类 第一种分法: 1.输入流 2.输出流 第二种分法: 1.字节流 2.字符流 第三种分法: 1.节点流 2.处理流 I/O当中的核心类: InputStream  <--------F ...

  8. wow.js使用方法

    近日,在做项目中,需要做到滚动条滑到某个位置时,才能显示动画,网上查询到有个wow.js可以达到要求,现在把使用方法做如下总结: wow.js演示地址 wow.js的github地址 使用方法真是超简 ...

  9. iOS推送通知

    推送通知 此通知非彼通知. NSNotification是抽象的,看不见的,但是可以监听,属于观察者模式的一种设计模式. 推送通知是可见的,能用肉眼看见的,是真正的和用户打交道的通知. 推送通知分为两 ...

  10. 【bzoj3991】 寻宝游戏

    http://www.lydsy.com/JudgeOnline/problem.php?id=3991 (题目链接) 题意 给出一个n个节点的带权树,m次操作每次修改一个关键点,求每次操作后,从其中 ...