题目链接: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. jquery中使用event.target的几点

    jquery中使用event.target的几点 1.this和event.target的区别: js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事 ...

  2. Debian下查看系统版本信息命令汇总

    Debian下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然. 1.odoo@debian64:~$ uname -a(Debian查看版本当前操 ...

  3. NIS 报错No such map passwd.byname. Reason: Can't bind to server which serves this domain

    在NIS—client端使用命令:ypcat passwd ,把错如上题, 原因:client端ypbind服务未启动解决方法:当然是启动ypbind了,命令:service ypbind start ...

  4. php命令行运行出现错误Call to undefined function curl_init()

    在windows命令行窗口下运行php命令,需要将php.exe所在的路径添加到Path环境变量,例如C:\wamp\bin\php\php5.4.3 启动Apache服务 在命令行中输入php te ...

  5. September 6th 2016 Week 37th Tuesday

    I only wish to face the sea, with spring flowers blossoming. 我只愿面朝大海,春暖花开. That scenery is beautiful ...

  6. device host global 函数要求

    转自:https://kheresy.wordpress.com/2007/11/05/nvidia-cuda-api%EF%BC%88%E4%B8%8A%EF%BC%89/ Function typ ...

  7. 用线框模式绘制多边形 glPolygonMode

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_TRIANGLES);//开始以g_ViewMode模式绘制 glColor3ub(182. ...

  8. linux crontab 学习

    安装crontab:[root@CentOS ~]# yum install vixie-cron[root@CentOS ~]# yum install crontabs/sbin/service ...

  9. mysql 得到重复的记录

    select devicetoken from client_user group by devicetoken having count(devicetoken)>1

  10. Swift - @IBDesignable和@IBInspectable

    前言: 用storyboard/xib搞项目时,一些属性在Interface Builder上时无法设置,比如常用的layer的一些属性cornerRadius,borderColor等 (有时没必须 ...