- 陶陶的名字
- 2013-08-18 16:56:23 @
###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 条评论
-
wqncft LV 8 @ 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