大牛帮忙看看哪里错了

###Block Code
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
char begin,tmp;
string name;
int st,end,nowpos,lastst;
int main()
{
//freopen("p1677.in","r",stdin);
ios::sync_with_stdio(false);
cin>>name;
int len=name.length(),len1;
begin=name[0];
st=0;
for(end=0;name[end+1]!=begin;end++);
len1=end-st+1;
for(int i=end+1;i<len;i++){
tmp=name[i];
if(tmp!=begin&&i<len-1){
nowpos++;
if(nowpos>=len1){
st=lastst;
while(i<len-1&&name[i+1]!=begin)i++;
if(i!=len-1){
end=i;
len1=end-st+1;
nowpos=len1-1;
}
else{
end=len-1;
len1=end-st+1;
}
}
else{
if(name[st+nowpos-1]!=tmp){
while(i<len-1&&name[i+1]!=begin)i++;
if(i!=len-1){
end=i;
len1=end-st+1;
nowpos=len1-1;
}
else{
end=len-1;
len1=end-st+1;
}
}
}
}
else if(i<len-1){
lastst=i;
nowpos=1;
}
if(i==len-1){
if(!(nowpos==len-1&&name[st+nowpos-1]==tmp)){
end=len-1;
len1=end-st+1;
}
}
}
cout<<len1;
}

1 条评论

  • @ 2013-08-18 16:58:29

    ###
    #include<iostream>
    #include<cstdio>
    #include<string.h>
    using namespace std;
    char begin,tmp;
    string name;
    int st,end,nowpos,lastst;
    int main()
    {
    //freopen("p1677.in","r",stdin);
    ios::sync_with_stdio(false);
    cin>>name;
    int len=name.length(),len1;
    begin=name[0];
    st=0;
    for(end=0;name[end+1]!=begin;end++);
    len1=end-st+1;
    for(int i=end+1;i<len;i++){
    tmp=name[i];
    if(tmp!=begin&&i<len-1){
    nowpos++;
    if(nowpos>=len1){
    st=lastst;
    while(i<len-1&&name[i+1]!=begin)i++;
    if(i!=len-1){
    end=i;
    len1=end-st+1;
    nowpos=len1-1;
    }
    else{
    end=len-1;
    len1=end-st+1;
    }
    }
    else{
    if(name[st+nowpos-1]!=tmp){
    while(i<len-1&&name[i+1]!=begin)i++;
    if(i!=len-1){
    end=i;
    len1=end-st+1;
    nowpos=len1-1;
    }
    else{
    end=len-1;
    len1=end-st+1;
    }
    }
    }
    }
    else if(i<len-1){
    lastst=i;
    nowpos=1;
    }
    if(i==len-1){
    if(!(nowpos==len-1&&name[st+nowpos-1]==tmp)){
    end=len-1;
    len1=end-st+1;
    }
    }
    }
    cout<<len1;
    }

  • 1

信息

ID
1677
难度
8
分类
字符串 | KMP 点击显示
标签
递交数
2299
已通过
214
通过率
9%
被复制
3
上传者