题目链接: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. 使用D3制作图表(1)--画布绘制

    使用D3绘制图表可以使数据更加直观. 使用D3前要先加载D3库,这里有两种方式,一种是在线加载<script type="text/javascript" src=" ...

  2. [转] Spring注解@Component、@Repository、@Service、@Controller区别

    原文地址:http://blog.csdn.net/zhang854429783/article/details/6785574 很长时间没做web项目都把以前学的那点框架知识忘光了,今天把以前做的一 ...

  3. 使用SFTP工具下载文件

    1. 打开SFTP会话 File->Connect SFTP Session  2. cd 到文件目录下 3. get 文件名称 sftp> get catalina.out 4. lpw ...

  4. css-画三角箭头

    .arrow { width:; height:; content: ""; border: solid 10px #7c7; display: block; border-top ...

  5. java-汉字转化拼音(纯java)

    1.转换所有的拼音 import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Set; public cl ...

  6. python-generator生成杨辉三角

    根据廖雪峰老师的评论区摘录. 1: def triangles(): L = [1] while True: yield L L1 = [0] + L[:] L = [L[i]+L1[i] for i ...

  7. dede的安装和配置

    dede的cms通常是,dede作为后台,前台可以自己换一套模版(后台貌似也跟着换掉,或者不换) 安装时候会检查目录读写权限,以及数据库配置 安装后,还需要登录到后台: 配置网站根网址 清除缓存 数据 ...

  8. PowerShell控制台快捷键

    按键 功能 ← 光标向左移动一个字符 Ctrl + ← 光标向左移动一个单词 → 光标向右移动一个字符 Ctrl + → 光标向右移动一个单词 Home键 光标移动到行首 End键 光标移动到行尾 D ...

  9. javaBean和Servlet有什么区别

    1.javabean无非就是里面有些set和get方法 2.servlet用来处理一些逻辑层 3.javabean.servlet.jsp分别对应M(odel).C(ontroller).V(iew) ...

  10. Android成长日记-LogCat

    1. Log日志级别 Log.v(tag,messag) //verbose模式,打印最详细的日志输出颜色为黑色 Log.d(tag,messag) //debug级别的日志,颜色为蓝色 Log.i( ...