UVA-10945 Mother Bear

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[200],b[200],c[100],d[100],k,z;
    int n,i,l;
    while(gets(d))
    {
        if(strcmp(d,"DONE")==0)
        {
            break;
        }
        l=strlen(d);
        for(i=0;d[i]!='\0';i++)
        {
            a[i]=tolower(d[i]);
        }
        a[l]='\0';
        for(i=0;i<l;i++)
        {
            if(ispunct(a[i]))
            {
                for(k=i;k<l;k++)
                {
                    a[k]=a[k+1];
                }
                i=0;
                l=l-1;
            }

        }
        a[l]='\0';
        for(i=0;i<l;i++)
        {
            if(ispunct(a[i]))
            {
                for(k=i;k<l;k++)
                {
                    a[k]=a[k+1];
                }
                i=0;
                l=l-1;
            }

        }
        a[l]='\0';
        for(i=0;i<l;i++)
        {
            if(a[i]==' ')
            {
                for(k=i;k<l;k++)
                {
                    a[k]=a[k+1];
                }
                i=0;
                l=l-1;
            }
        }
        a[l]='\0';
        strcpy(c,a);
        reverse(c,c+strlen(c));
        if(strcmp(c,a)==0)
        {
            printf("You won't be eaten!\n");
        }
        else
        {
            printf("Uh oh..\n");
        }
    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment