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

Help!!! WA on test 4
Posted by Invisible 13 May 2005 22:41
Please help me, I can't find error in my program, but WA4

#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10000
int main() {
    char s1[SIZE], *s2;

    int i, k, t, j, done;

    cin >> s1;
    s2 = (char*) calloc (strlen (s1)+1, sizeof(char));

    k = strlen (s1) - 1;


    for (i = k; i >= 0; i--)
        s2[i] = s1[k - i];

    done = 0;

    for (i = 0; i <= k; i++) {
        for (j = i; j <= k; j++) {
            if ( s2[j-i] != s1[j] ) {
                done = 1;
                break;
            }
        }
        if (done == 0) {
             cout << s1;
            for (t = k - i + 1; t <= k; t++)
                cout << s2[t];

            cout << endl;
            break;
         }
         done = 0;
    }
    delete s2;

    return 0;
}
Re: Help!!! WA on test 4
Posted by Burunduk1 14 May 2005 02:31
For test 'aba' right answer is 'ababa'
Read the problem more attentively. String should be not empty!

Good luck!
Re: Help!!! WA on test 4
Posted by Invisible 14 May 2005 04:37
Thanks, now all right, next time I'll be more attentive