2820. 围栏

10175101151

坑:1,无数据时输出0
2,有数据,没有围栏输出1

柴柴柴拆柴柴

正则表达式解法

#include <bits/stdc++.h>

using namespace std;

int main()
{
    regex pattern("(\\|)?(-\\|)+(-)?|(-)?(\\|-)+(\\|)?|(\\|)|(-)");
    string s;
    smatch sm;
    int imax=0;

    getline(cin,s);
    string::const_iterator iterStart=s.begin();
    string::const_iterator iterEnd=s.end();

    while(regex_search(iterStart,iterEnd,sm,pattern)){
        if(sm[0].length()>imax)
            imax=sm[0].length();
        iterStart=sm[0].second;
    }

    cout<<imax<<endl;

    return 0;
}
Li Dao

长度可能为0哦,注意特判

include

using namespace std;
string strs;

int main()
{
cin>>strs;
int ll=strs.length();
int len=0,ans=0;
for(int i=0;i0 && strs[i-1]!=strs[i]) {len++;ans=max(ans,len);}
else {len=1;ans=max(ans,len);}
cout<<ans<<endl;
return 0;
}

zzpzbl

include

include

int main(){
char str[100];
int a[100]={0};
while(scanf(“%s”,str)==1){
int cnt=0;
for(int i=1; i<strlen(str); i++){
if(str[i]!=str[i-1])a[cnt]++;
else cnt++;
}
int max=a[0];
for(int i=1; i<=cnt; i++)
if(a[i]>max)max=a[i];
printf(“%d\n”,max+1);
}
}

carpediem

天坑啊!!!
[em:03][em:02][em:03][em:03] 题目表述不明。。。白白提交了十多次啊!!!

Rodriguez

include

include

include

include

using namespace std;
int main()
{
char str[50];
scanf(“%s”,str);
int l=strlen(str);
int num[50];
for(int u=0;u<50;u++)num[u]=0;
int i=0;
while(i<l){
int a=1;
int t=i;
if(t<l-1){
while(str[t]!=str[t+1]&&t<l-1){
a++;
t++;
}}
num[i]=a;
i++;
}
sort(num,num+50);
cout<<num[49]<<endl;
return 0;
}

Weaver_zhu

巨坑。。。记得用getline

IWani-Z

这题分虚高,应该2分以下

Zoey

天坑的题附近总有许多discussions.

carpediem

第一句话有歧义啊!!!
[em:13]
同学,咱俩是被一起坑了。。。
[em:14]

10195102468

include

using namespace std;
int main()
{
string s;
cin>>s;
int l =0,r = 0;
int max_ = 0;
int len = 0;
if (s.length() == 0)
cout<<0<<endl;
if (s.length() == 1) cout<<1<<endl;
else{

    while( r < s.length())
    {
        while ((((s[r - 1] == '|')&(s[r] == '-')) == 1) || (((s[r - 1] == '-') & (s[r] == '|')) == 1))
        {
            r ++;
        }
        len = r - l;
        max_ = max(len,max_);
        l = r;
        r++;
    }
    cout<<max_<<endl;
}

}

回调地狱

这题题意是不是有误啊,长度为1居然也能算围栏。

CoolCarrot

简单的dp解法

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int max=1,i,n;
    int dp[52];
    char a[100];
    scanf("%s\n", a);
    n=strlen(a);
    dp[0] = 1;
    for(i=1; i<n; ++i){
        if(a[i] != a[i-1])
            dp[i] = dp[i-1] + 1;
        else
            dp[i] = 1;
        if(dp[i] > max)
            max = dp[i];
    }

    printf("%d",max);
    return 0;
}
三七茧茧

要用gets(s),不能使用scanf(“%s”,s);

Suzuki_Yuuta
void solve(string s) {
    if (!s.length()) {
        cout << 0 << endl;
    } else {
        int maxLen = 1, currentLen = 1;
        for (int i = 1; i < s.length(); i++) {
            if (s[i] != s[i - 1]) {
                currentLen++;
                if (currentLen > maxLen) {
                    maxLen = currentLen;
                }
            } else {
                currentLen = 1;
            }
        }
        cout << maxLen << endl;
    }
}
wwliang

Python solution
import sys

s = sys.stdin.readline().strip()

res = 0
cur = 0
prev = None
for i in range(len(s)):
if i == 0:
cur = 1
else:
cur = cur + 1 if s[i] != prev else 1

prev = s[i]
res = max(cur, res)

print(res)

会奔跑的bug

只需要考量前后两个字符是否一致即可,python3的解决方法:
import sys

s = sys.stdin.readline().strip()
len_s = len(s)
if len_s == 0:
print(0)
elif len_s == 1:
print(1)
else:
all_len = []
one_len = 1
for i in range(len_s-1):
if s[i] != s[i+1]:
one_len = one_len +1
all_len.append(one_len)
else:
all_len.append(one_len)
one_len = 1
print(max(all_len))

10185101141

可以scanf的哦

include

int main()
{
char a[100];
int i=1,j=0,k=0;
scanf(“%s”,a);
for(;a[j]!=’\0’;j++){
if(a[j]==a[j+1]||a[j+1]==’\0’){
if(k<i)
k=i;
i=1;
}
else
i++;
}
printf(“%d\n”,k);
return 0;
}

Kyrie_Irving

include

include

using namespace std;
int main()
{
string s;
cin>>s;
int cnt=1;
int max_num=1;
for(int i=1; imax_num) max_num=cnt;
}
cout<<max_num<<endl;
}

你当前正在回复 博客/题目
存在问题!