401 palindromes WA help

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Re: 401 palindromes WA help

Postby L I M O N » Sat Nov 01, 2008 6:55 pm

L I M O N
Learning poster
 
Posts: 58
Joined: Wed Dec 31, 2003 8:43 am
Location: Dhaka, Bangladesh

Re: 401 palindromes WA help

Postby lprell » Tue Aug 09, 2011 11:06 pm

Need some help.

I keep getting WA. Checked with all output in threads and it seems ok. Extra lines also ok.

Heres my code.
Thanks for the help and sorry my bad coding. Still learning...
Code: Select all
# include <stdio.h>
# include <stdlib.h>

void inverte (char *string)
{
   int i,j;
   char h;
   for (i=0, j=strlen(string)-1; i<j; ++i, --j)
   {
      h= string[i];
      string[i]= string[j];
      string[j]= h;
   }
}

int reverso (char *string)
{
   char r[13]="AHIMOTUVWXY18";
   int i,j,aux=0;
   for (i=0; i<strlen(string); ++i)
   {
      for (j=0; j<13; ++j)
      {
         if (string[i]==r[j])
            aux++;
      }
   }
   return aux;
}

void substitui (char *string)
{
   int i,aux;
   for (i=0; i<strlen(string); ++i)
   {
      if (string[i] == 'E')
      {
         string[i]= '3';
         aux++;
      }
      else
         if (string[i] == 'J')
         {
            string[i]= 'L';
            aux++;
         }
         else
            if (string[i] == 'L')
            {
               string[i]= 'J';
               aux++;
            }
            else
               if (string[i] == 'Z')
               {
                  string[i]= '5';
                  aux++;
               }
               else
                  if (string[i] == '2')
                  {
                     string[i]= 'S';
                     aux++;
                  }
                  else
                     if (string[i] == '3')
                     {
                        string[i]= 'E';
                        aux++;
                     }
                     else
                        if (string[i] == '5')
                        {
                           string[i]= 'Z';
                           aux++;
                        }
                        else
                           if (string[i] == 'S')
                           {
                              string[i]= '2';
                              aux++;
                           }
   }
}

int main (void)
{
   char s[50],t[50];
   int i,cont,aux;
   while (gets(s) != EOF)
   {
      cont=-1;
      strcpy(t,s);
      inverte(t);     
      if (strcmp(s,t)==0)
      {
         cont=1;
      }
      substitui(t);
      if (strcmp(s,t)==0)
      {
         cont--;
      }
      aux=reverso(t);
      if (cont==-1)
      {
         for (i=0; i<strlen(t); ++i)
         {
            printf("%c", s[i]);
         }
         printf(" -- is not a palindrome.\n\n");
      }else
         if (cont==1)
         {
            for (i=0; i<strlen(s); ++i)
            {
               printf("%c", s[i]);
            }
            printf(" -- is a regular palindrome.\n\n");
         }else
            if (cont==-2)
            {
               for (i=0; i<strlen(s); ++i)
               {
                  printf("%c", s[i]);
               }
               printf(" -- is a mirrored string.\n\n");
            }else
               if (cont==0)
               {
                  for (i=0; i<strlen(s); ++i)
                  {
                     printf("%c", s[i]);
                  }
                  if (aux==strlen(s))
                     printf(" -- is a mirrored palindrome.\n\n");
                  else
                     printf(" -- is a regular palindrome.\n\n");
               }
   }
   return 0;
}

lprell
New poster
 
Posts: 5
Joined: Fri Jun 17, 2011 8:56 am

Re: 401 palindromes WA help

Postby sith » Wed Jul 04, 2012 11:21 pm

Hello

I believe that my solution is correct but I've got WA.
Maybe the bad output formatting is the reason of WA?


Code: Select all
AC

sith
Learning poster
 
Posts: 67
Joined: Sat May 19, 2012 7:46 pm

Previous

Return to Volume IV

Who is online

Users browsing this forum: No registered users and 1 guest