Codeforces Round #375 (Div. 2) - B
题目链接: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的更多相关文章
- Codeforces Round #375 (Div. 2) - D
题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...
- Codeforces Round #375 (Div. 2) - C
题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...
- Codeforces Round #375 (Div. 2) - A
题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟
B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...
- 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 ...
- 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个人演唱歌曲 ...
随机推荐
- 魅族MX3\MX2 在MTP模式下恢复手机误删数据教程
昨天帮室友的魅族mx3升级系统,结果不小心把他手机里的照片删了.但是自从flyme升级到3后,以前的U盘模式就改成了MTP模式,这样再连接电脑后就没办法用电脑上的数据恢复软件恢复数据了,因为压根就检测 ...
- eclipse下使用git下载和上传项目
简单配置,填入我们的用户名和邮箱 >>Preferences>Team>Git>Configuration 点击Add Entry,在弹出框里面输入key和value的值 ...
- 如何将.il、.res文件封装成dll文件
将你的.il..res文件保存在你的硬盘上,如下图: 我存放的路径在E盘的test文件夹中,我们开始封装了咯.进入DOS命令,如下图: 我们通过DOS命令先进入.il..res文件目录,如下图: 然后 ...
- osg::NodeVisitor中计算一个节点对应的世界变换矩阵、法向量、顶点坐标
class MyNodeVisitor:public osg::NodeVisitor { pulic: MyNodeVisitor():osg::NodeVisitor(osg::NodeVisit ...
- 当对服务器端返回的极光推送数据请求时,AFN 的 GET 请求失败如何解决
代码段 控制台 只需在 manager 那里添加一行代码即可 //传入json格式数据,不写则普通post manager.requestSerializer = [AFJSONReque ...
- mongodb3.x版本用户管理方法
db.auth() 作用:验证用户到数据库. 语法: db.auth( { user: <username>, pwd: <password>, mechanism: < ...
- TCP/IP五层模型
(2)TCP/IP五层模型的协议 应用层 传输层 网络层 数据链路层 物理层 物理层:中继器.集线器.还有我们通常说的双绞线也工作在物理层 数据链路层:网桥(现已很少使用).以太网交换机(二层 ...
- Cocoapods的安装报错 - Error installing pods:activesupport requires Ruby version >=2.2.2
1.打开终端 2 移除现有 Ruby 默认源 输入以下指令 $gem sources --remove https://rubygems.org/ 3.使用新的源 输入以下指令 $gem source ...
- vpn,可以连接上,但是不能访问局域网内共享的文件怎么办
不选用VPN的上网关,就可以识别域用户访问共享文件的权限了,在VPN连接的属性里双击TCP/IP协议-高级-去掉勾选"在远程网络上使用默认网关".
- Jquery.Datatables 基本创建方法
基本创建 <!--定义操作列按钮模板--> <script id="tpl" type="text/x-handlebars-template" ...