|
|
вернуться в форумWhy WA 4????????????? I can't understand what's wrong with my code: #include <iostream> #include <string> using namespace std; bool isPalindrom(string str, unsigned n){ unsigned num1=n, num2=str.size()-n-1, num; if(num1>num2) num=num2; else num=num1; for(unsigned a=0; a<=num; a++) if(str[n-a]!=str[n+a]) return false; return true; } int main(){ string s1; unsigned x; cin>>s1; if(s1.size()==1){ cout<<s1; return 0; } string str; for(unsigned a=s1.size()/2; a<s1.size(); a++) if(isPalindrom(s1, a)){ x=a; for(unsigned a=0; a<x; a++) str+=s1[a]; str+=s1[x]; for(int b=x-1; b>=0; b--) str+=s1[b]; if(s1 < str){ cout<<str<<endl; return 0; } str.erase(); } return 0; } Re: Why WA 4????????????? 1) Please, delete your code 2) Read task more carefully: "You are to find a NONEMPTY word S2 of the minimal length that S1S2 - is a palindrome." I think your solution will fail on testcase like "SOS" |
|
|