|
|
вернуться в форумTLE on #25(help!!!) #include <iostream> #include <cstring> #include <vector> using namespace std; int main() { char str[20000],str2[10000],str3[10000]; unsigned int len; unsigned int i,j,k; vector<char>check; char ch;
while(gets(str)) { len=strlen(str);
if(len==1) cout<<str[0]<<str[0]<<endl;
else {
for(i=0;i<len;i++) str2[i]=str[len-1-i];
if(strncmp(str,str2,len)==0) { for(i=1;i<=len;i++) { for(j=i;j<len;j++) { ch=str[j]; check.push_back(ch); }
for(j=0;j<check.size();j++) { str2[j]=check[j]; str3[j]=check[check.size()-1-j]; }
if(strncmp(str2,str3,check.size())==0) { for(k=0;k<i;k++) str[len+k]=str[i-k-1];
for(k=0;k<len+i;k++) cout<<str[k]; cout<<endl;
check.clear(); break; } check.clear(); } }
else { for(i=0;i<len;i++) { for(j=i;j<len;j++) { ch=str[j]; check.push_back(ch); }
for(j=0;j<check.size();j++) { str2[j]=check[j]; str3[j]=check[check.size()-1-j]; }
if(strncmp(str2,str3,check.size())==0) { for(k=0;k<i;k++) str[len+k]=str[i-k-1];
for(k=0;k<len+i;k++) cout<<str[k]; cout<<endl;
check.clear(); break; } check.clear(); } } }
}
return 0; } Re: TLE on #25(help!!!) My freind i not c++ but I do at java and AC 0.265 My main function code that while(true){ if(n+1==k-n1)if(ch[n]==ch[k-n1])break; if(n==k-n1)break; if(ch[n]==ch[k-n1]){ n++; n1++; } else{ k1++; n=k1; n1=1; } } |
|
|