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, ...
随机推荐
- extjs store的操作
先来个声明,看着不错,贴过来的,没都测试过. Store.getCount()返回的是store中的所有数据记录,然后使用for循环遍历整个store,从而得到每条记录. 除了使用getCount() ...
- C++中函数的默认参数和C语言中volatile的学习
1.函数默认参数 1 int func(int a,int b=10) 2 { 3 return a*b; 4 } 5 6 int main() 7 { 8 int c=func(2); 9 cout ...
- iOS开发小技巧--iOS中设置applicationIconBadgeNumber遇到的问题
iOS中设置applicationIconBadgeNumber 在iOS7中直接设置applicationIconBadgeNumber没有问题,但是在iOS8之后设置applicationIcon ...
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- javascript 公共方法 集合
数组去重: Array.prototype.unique1 = function () { var n = []; //一个新的临时数组 for (var i = 0; i < this.len ...
- Jetty应用服务器的安装详解
Jetty是一个开源的Servlet容器和应用服务器,它极度轻量级.高便携性.功能强大.灵活和扩展性好,而且支持各种技术如SPDY.WebSocket.OSGi.JMX.JNDI和JAAS.Jetty ...
- 算法与数据结构之折半查找(C语言)
#include <stdio.h> #include<stdlib.h> int binsearch(int x,int v[],int n);//函数声明 int main ...
- C++ 复制控制之复制构造函数
7月26日更新: 过了这么长的时间回过头来看,发现文章中有几个点说错(用红字标出): 构造函数不是只有唯一一个参数,它也可以是多参数形式,其第二参数及后继以一个默认值供应. 不是没有声明复制控制函数时 ...
- 【poj2114】 Boatherds
http://poj.org/problem?id=2114 (题目链接) 题意 给出一棵树,问是否存在两点间的距离为K. Solution 点分治嘛,跟poj1741差不多.. 然而为什么我调了一个 ...
- bzoj4419[SHOI2013]发微博
题意:给你一个初始没有边,点权均为0的无向图,三种操作:加边,删边,选择一个点将当前与之相邻的点(不包括自身)的点权+1,询问最后所有点的点权. 据说正解是set维护每个人的朋友,然后考虑每次加边.删 ...