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

题意:给定一个字符串。只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词。现在要你输出括号外面的单词的最大长度和括号里面出现的单词数目

思路:按照题目模拟就好了。写的比较搓。

#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<math.h>
#include<time.h>
#include<vector>
#include<iostream>
using namespace std;
typedef long long int LL;
const int INF = 0x3f3f3f3f;
const int MAXN = + ;
int n;
char str[MAXN];
int main(){
while (~scanf("%d", &n)){
scanf("%s", str);
bool inner = false; int maxlen = , cnt = ;
for (int i = ; i<strlen(str); i++){
if (str[i] == '_'){
continue;
}
if (str[i] == '('){
int k = i + ; bool haschar = false;
for (; k<strlen(str); k++){
if (str[k] == ')'){
cnt += (haschar ? : );
i = k; break;
}
if (str[k] == '_'){
cnt += (haschar ? : );
haschar = false;
}
else{
haschar = true;
}
}
}
else{
int k = i; int tmplen = ;
for (; k <= strlen(str); k++){
if (k == strlen(str)){
maxlen = max(maxlen, tmplen);
i = k;
break;
}
else if (str[k] == '_'){
maxlen = max(maxlen, tmplen);
tmplen = ;
continue;
}
else if (str[k] == '('){
maxlen = max(maxlen, tmplen);
i = k - ;
break;
}
else{
tmplen++;
}
}
}
}
printf("%d %d\n", maxlen, cnt);
}
return ;
}

Codeforces Round #375 (Div. 2) - B的更多相关文章

  1. Codeforces Round #375 (Div. 2) - D

    题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...

  2. Codeforces Round #375 (Div. 2) - C

    题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...

  3. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  4. Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树

    F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...

  5. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  6. Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心

    D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...

  7. Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟

    B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...

  8. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  9. Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心

    http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...

随机推荐

  1. 【linux】学习5

    鸟哥那本书第11章的内容 管理整个计算机硬件的是操作系统的内核(kernel),内核是需要保护的,我们一般用户只能通过shell来跟内核通信.Shell是用户操作系统的接口 cat  /etc/pas ...

  2. 【python】mysqlDB转xml中的编码问题

    背景:有mysql数据库,将数据从数据库中读取,并存储到xml中 采用了MySQLdb和lxml两个库 具体编码处理过程如下: . 指定mysql的编码方式 .取数据库data->判断data类 ...

  3. validation验证器指定action中某些方法不需要验证

    今天写代码时,遇到个问题,在一个输入数据的页面有一个按钮,单击会发出请求从数据库中取数据,在这里出现问题,单击该按钮,配置的validation起作用,该请求没有到达后台的action 点击按钮选择作 ...

  4. 20145213《Java程序设计》第八周学习笔记

    20145213<Java程序设计>第八周学习笔记 教材学习内容总结 "桃花春欲尽,谷雨夜来收"谷雨节气的到来意味着寒潮天气的基本结束,气温回升加快.刚出冬的我对于这种 ...

  5. 虚拟机中的centos在nat模式下连不上外网

    这两天需要配置ftp服务器,可是虚拟机在nat模式下死活连不上外网,主机能够通过该ssh与虚拟机进行连接,虚拟机也能ping同一网段主机的IP地址,但就是ping不通外网, 开始我是这样配置的: 主机 ...

  6. Collection 集合类

    ArrayList: 基于动态数组的List 它有两个重要的变量,size为存储的数据的个数.elementData 数组则是arraylist 的基础,因为他的内部就是通过这个数组来存储数据的. p ...

  7. CABasicAnimation animationWithKeyPath 一些规定的值

    CABasicAnimation animationWithKeyPath Types When using the ‘CABasicAnimation’ from the QuartzCore Fr ...

  8. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  9. centos 安装 py pyhs2

    1. yum install gcc-c++ cyrus-sasl-develpip2.7 install pyhs2 --->好像不行,在试试 用于 hive thrift 访问 2. os. ...

  10. Jquery.Datatables dom表格定位

    Datatables会添加一些控制元素在表格的周围,比如默认状态下改变每页显示条数(l)的空间在左上角,即使搜索框(f)在右上角,表格的信息(i)显示在左下角,分页控件(p)显示在右下角. 这些控件在 ...