2891: E--围栏

时间限制: 1 Sec  内存限制: 128 MB

提交: 91  解决: 24

题目描述

一串连续字符被称作围栏当且仅当它由间隔的‘|’和‘-’组成。比如“|-|-|-|”或“|-|”(引号仅供说明)。注意“|-||-|”或者“--”不是围栏,因为每个都包含了两个或两个以上的相同连续字符。给你一个字符串,请找出它的最长的一个可以称作围栏的子串长度。

输入

长度为n(0≤n≤50)的字符串s,s只包含‘| ’、‘-’字符,

有多组字符串,每个一行。

输出

在一行中输出最长的围栏长度值。

样例输入

|-
|||-||--|--|---|-||-|-|-|--||---||-||-||-|--||

样例输出

2
8

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include <iostream>
#include <cstring>
using namespace std;
void fun(string s)
{
int len=s.length();
if(len<=1)
{
cout<<len<<'\12';
return;
}
int max=0,t=1;
if(s[1]!=s[0])max=2;
else max=1;
t=max;
for(int i=2; i<len; i++)
{
if(s[i]!=s[i-1])
t++;
else
{
max=max>t?max:t;
t=1;
}
}
max=max>t?max:t;
cout<<max<<'\12';
}
int main()
{
string str;
while(cin>>str)
{
fun(str);
}
return 0;
}

YTU 2891: E--围栏的更多相关文章

  1. ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)

    1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 136[Submit][Status ...

  2. ytu 1058: 三角形面积(带参的宏 练习)

    1058: 三角形面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 190  Solved: 128[Submit][Status][Web Boar ...

  3. 【POJ】2891 Strange Way to Express Integers

    http://poj.org/problem?id=2891 题意:求最小的$x$使得$x \equiv r_i \pmod{ a_i }$. #include <cstdio> #inc ...

  4. 地理围栏算法解析(Geo-fencing)

    地理围栏算法解析 http://www.cnblogs.com/LBSer/p/4471742.html 地理围栏(Geo-fencing)是LBS的一种应用,就是用一个虚拟的栅栏围出一个虚拟地理边界 ...

  5. ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)

     小鼠迷宫问题 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 1  Solved: 1 [Submit][Status][Web Board] Desc ...

  6. 【POJ】【2891】Strange Way to Express Integers

    中国剩余定理/扩展欧几里得 题目大意:求一般模线性方程组的解(不满足模数两两互质) solution:对于两个方程 \[ \begin{cases} m \equiv r_1 \pmod {a_1} ...

  7. 【GPS】 数据围栏

    1.记录gps信息,定位类型  gps  agps ,偏移量 2.根据id检索用户 gps 历史记录 3.创建围栏 4.围栏内用户检索(先实现 圆形和矩形) 5.判断一个点是否进出围栏 应用场景: o ...

  8. poj 2891 Strange Way to Express Integers(中国剩余定理)

    http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...

  9. 数学#扩展欧几里德 POJ 1061&2115&2891

    寒假做的题了,先贴那时写的代码. POJ 1061 #include<iostream> #include<cstdio> typedef long long LL; usin ...

随机推荐

  1. zoj 1949 Error Correction

    Error Correction Time Limit: 2 Seconds      Memory Limit: 65536 KB A boolean matrix has the parity p ...

  2. Copy List with Random Pointer (Hash表)

    A linked list is given such that each node contains an additional random pointer which could point t ...

  3. F - The Minimum Length

    F - The Minimum Length HUST - 1010 #include<cstdio> #include<cstring> #include<iostre ...

  4. 转 Linux里设置环境变量的方法(export PATH)

    1.动态库路径的设置 Linux下调用动态库和windows不一样.linux 可执行程序是靠配置文件去读取路径的,因此有些时候需要设置路径 具体操作如下export LD_LIBRARY_PATH= ...

  5. vue2.0单元测试(一)

    1.在vue init webpack XXX创建项目的时候 最后2步选择YES就启动了vue单元测试开始了   2.测试是使用karma+mocha框架来实现的方法,安装虚拟浏览器模块Phantom ...

  6. 报错: The type ByteInputStream is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  7. 【Todo】开个文章学VUE咯

    2017年FE架构组制定的框架选型主导为VUE.看了一下VUE的介绍,很不错. 开学~ https://www.zhihu.com/question/38213423 这个里面有VUE应用和背景的一些 ...

  8. c++之NVI手法

    non-virtual interface(NVI)手法:令用户通过public non-virtual成员函数间接调用private virtual函数,将这个non-virtual函数称为virt ...

  9. Android NFC近场通信02----读写卡的准备工作

                        Android NFC近场通信02----读写卡的准备工作      因为公司接了一个听上去感觉比較NB的项目.给某油田做派工系统 .并由小女子负责Androi ...

  10. [Unit Testing] Unit Test a Function that Invokes a Callback with a Sinon Spy

    Unit testing functions that invoke callbacks can require a lot of setup code. Using sinon.spy to cre ...