Tuesday, September 26, 2017

UVa problem solution 10945 - Mother bear


problem link:


Discuss: Just check each string palindrome or not.there is no tricky part in this programm

try your self before see the code



#include<bits/stdc++.h>
using namespace std;
void rev(string &str)
{
    int n;
    n=str.length();
    for(int i=0;i<n/2;i++)
    {
        swap(str[i],str[n-i-1]);
    }
}
int main()
{
 char str[100000],ch;
    while(gets(str))
    {
        if(!strcmp(str,"DONE"))
            break;
        int n,i,j,cnt=0,flag=0;
        string solid,check;
        n=strlen(str);
      //cout <<str<<endl;
        for(i=0;i<n;i++)
        {
           ch=towlower(str[i]);
            if(ch>='a'&&ch<='z')
                solid.push_back(ch);
               // cout <<ch<<' ';
        }
        //cout <<solid<<endl;
        check=solid;
        rev(check);
            if(check==solid)
               cout <<"You won't be eaten!"<<endl;
                      else
                cout <<"Uh oh.."<<endl;

    }
    return 0;
}

No comments:

Post a Comment