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;
}
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{
坑:1,无数据时输出0
2,有数据,没有围栏输出1
正则表达式解法
长度可能为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;
}
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);
}
}
天坑啊!!!
[em:03][em:02][em:03][em:03] 题目表述不明。。。白白提交了十多次啊!!!
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;
}
巨坑。。。记得用getline
这题分虚高,应该2分以下
天坑的题附近总有许多discussions.
第一句话有歧义啊!!!
[em:13]
同学,咱俩是被一起坑了。。。
[em:14]
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{
}
这题题意是不是有误啊,长度为1居然也能算围栏。
简单的dp解法
要用gets(s),不能使用scanf(“%s”,s);
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
print(res)
只需要考量前后两个字符是否一致即可,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))
可以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;
}
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;
}