ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1354. Palindrome. Again Palindrome

Why WA 4?????????????
Posted by Black Raven 30 Mar 2005 13:13
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?????????????
Posted by Red Hot Chili Pepper 31 Mar 2005 02:28
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"