Page 3 of 5

Re: 10945 - Mother Bear

Posted: Fri Aug 12, 2011 4:02 pm
by aur
I have been getting a weird WA

here's my code :

Code: Select all

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{

    string s;
   while(getline(cin,s)){
      if(s=="DONE")
        break;
    for(int i=0;i<s.length();i++)
      if(s[i] == ' ' || s[i]== '.' || s[i]==',' || s[i]=='!' || s[i]=='?')
        s.erase(i,1);
    
    for(int i=0;i<s.length();i++)
      if(s[i] == ' ')
        s.erase(i,1);
    
    string::reverse_iterator rit;
    int i=0,counter=0;
  for ( rit=s.rbegin() ; rit < s.rend(); rit++,i++ ){
         if(*rit == s[i] || *rit+32==s[i] || *rit-32==s[i])
           counter++;
           }

  if(counter==s.length())
    cout<<"You won't be eaten!"<<endl;
  else cout<<"Uh oh.."<<endl;
    
}  
    
 return 0;
}

Re: 10945 - Mother Bear

Posted: Fri Aug 12, 2011 6:09 pm
by Seldaski
I don't know why I got WA, plz Help Me...I am new in UVa Online Judge :-?

Here is My Code,

#include<iostream>
#include<cmath>;
#include<vector>
using namespace std;
int main()
{
string S;
int Characters=0,Punc=0;
int X,i,M=0;
vector<string>Strs;

while(getline(cin,S)&&S!="DONE")
{
Strs.push_back(S);
}
while(M<Strs.size())
{
Characters=0; Punc=0;
S=Strs[M];
X=S.size()-1;
for(i=0;i<=ceil((double)S.size()/2);i++)
{
if(S.size()%2==0 && i==ceil((double)S.size()/2)&&Punc==0) break;
if(X == ceil((double)S.size()/2)-1&& i==ceil((double)S.size()/2)-1)
{Punc++;break;}

if(S == '.'||S == ','||S == '?'||S == '!'||S == ' ')
{
Punc++;
continue;}

if(S[X] == '.'||S[X] == ','||S[X] == '?'||S[X] == '!'||S[X] == ' ')
{
i=i-1;
X--;
Punc++;
continue;
}
if(S == toupper(S[X]) || S == tolower(S[X]))
Characters++;
X--;
}

if(Characters*2+Punc == S.size())
{cout<<"You won't be eaten!"; if(M!=Strs.size()-1) cout<<endl;}
else{ cout<<"Uh oh.."; if(M!=Strs.size()-1) cout<<endl;}
M++;
}
// system("pause");
return 0;
}

Thanks,

10945 - Mother Bear WA why? Anyone help me please

Posted: Wed Dec 28, 2011 6:32 pm
by uvasarker
Actually, I have seen the previous posted topic of this problem and try almost all of the given test cases and my program gives the right. But, in judge verdict give me WA.
Why? Please, help me please. Here is my code.

Code: Select all

#include<cstdio>
#include<sstream>
#include<cctype>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;

int main()
{
	char in[1000000];
	while(gets(in))
	{
		if(in[0]!='\0')
		{
			if( (in[0]=='D' && in[1]=='O' && in[2]=='N' && in[3]=='E' && in[4]=='\0')) break;
			char store[1000000],rev[1000000];
			unsigned long I=0, len=strlen(in);
			int p=0, fag=0;
			for(unsigned long i=0 ; i<=len ; i++)
			{
					if(isalpha(in[i]))
					{
							store[I]=tolower(in[i]);
							I++;
					}
			}
			for(unsigned long i=0 ; i<I ; i++)
			{
					rev[i]=store[I-1-i];
			}			
			
			for(unsigned long i=0 ; i<I ; i++)
			{
				fag=1;
					if(store[i]!=rev[i])
					{
						p=1;
						break;
					}
			}
			if(fag==1)
			{
				if(p==0)
					cout<<"You won't be eaten!"<<endl;
				else
					cout<<"Uh oh.."<<endl;
		
				p=0; fag=0;
				for(unsigned long i=0 ; i<I ; i++)
				{
						store[i]=rev[i]='\0';
				}
			}
		}
		else if(in[0]=='\0') cout<<"You won't be eaten!"<<endl;
	}
	
	return 0;
}


Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Fri Jan 13, 2012 1:38 am
by brianfry713
My AC code prints "You won't be eaten!" for a line containing only a space. Yours prints nothing.

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Fri Jan 13, 2012 4:34 pm
by uvasarker
Still WA please give more test cases....

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Sun Jan 15, 2012 5:07 pm
by uvasarker
Hi, guys what is it you post?

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Thu Jan 19, 2012 2:56 am
by brianfry713
Post your updated code.

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Thu Jan 19, 2012 7:26 pm
by uvasarker
Here, is my updated code:

Code: Select all

#include<cstdio>
#include<sstream>
#include<cctype>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;

int main()
{
	char in[1000000];
	while(gets(in))
	{
		if(in[0]!='\0' && in[0]!=' ')
		{
			if( (in[0]=='D' && in[1]=='O' && in[2]=='N' && in[3]=='E' && in[4]=='\0')) break;
			char store[1000000],rev[1000000];
			unsigned long I=0, len=strlen(in);
			int p=0, fag=0;
			for(unsigned long i=0 ; i<=len ; i++)
			{
					if(isalpha(in[i]))
					{
							store[I]=tolower(in[i]);
							I++;
					}
			}
			for(unsigned long i=0 ; i<I ; i++)
			{
					rev[i]=store[I-1-i];
			}			
			
			for(unsigned long i=0 ; i<I ; i++)
			{
				fag=1;
					if(store[i]!=rev[i])
					{
						p=1;
						break;
					}
			}
			if(fag==1)
			{
				if(p==0)
					cout<<"You won't be eaten!"<<endl;
				else
					cout<<"Uh oh.."<<endl;
		
				p=0; fag=0;
				for(unsigned long i=0 ; i<I ; i++)
				{
						store[i]=rev[i]='\0';
				}
			}
		}
		else if(in[0]=='\0' || in[0]==' ') cout<<"You won't be eaten!"<<endl;
	}
	
	return 0;
}


Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Wed Jan 25, 2012 2:26 am
by brianfry713
Try the input _a_b_c with the underscores as spaces.
It should print Uh oh..

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Wed Jan 25, 2012 3:17 pm
by uvasarker
Hi, brother
Thank you, Thank you, Thank you
Thank you very much
Thanks a lot...

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Tue Jul 17, 2012 7:50 pm
by sumit saha shawon
what is my problem?All of my input and output is ok.But I am getting WA. :x
my code is:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[3000],str1[3000],str2[30000];
while(gets(str))
{
int i,j,k,len;
if(strcmp(str,"DONE")==0)
break;
len=strlen(str);
for(i=0; i<len; i++)
str=toupper(str);
k=0;
for(i=0;i<len; i++)
if(str>='A' && str<='Z')
str2[k++]=str;
i=0;
for(j=k-1; j>=0; j--)
str1[i++]=str2[j];
// puts(str1);
//puts(str2);
if(strcmp(str1,str2)==0)
printf("You won't be eaten!\n");
else
printf("Uh oh..\n");
}
return 0;
}

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Wed Jul 18, 2012 2:18 am
by brianfry713
Null terminate the strings before you run strcmp()

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Fri Jul 20, 2012 3:00 pm
by sumit saha shawon
thanks I have got AC :)

Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Sun Oct 07, 2012 2:59 am
by Kashmir
Hello everyone!
Well, I've got a problem with this. I keep getting WA, and I can't find what's wrong. :(
Can anybody help me?
This is my code:

Thanks. :D

Code: Select all

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define REG 10
#define LEN 10
#define ES_PALINDROMO "You won't be eaten!"
#define NO_ES_PALINDROMO "Uh oh.."
#define ENTRADA_INVALIDA "Error"

int caracterValido( char ** s , int i );

void main()
{
    char string[REG][LEN], * fin, * s;
    int i = 0, j;

    fflush( stdin );

    if( !gets( string[i] ) )
    {
        puts( ENTRADA_INVALIDA );
        exit(1);
    }

    while( strcmp( string[i] , "DONE") != 0 && i < REG-1 && strlen( string[i] ) < LEN )
    {
        fflush( stdin );

        i++;

        if( !gets( string[i] ) )
        {
        puts( ENTRADA_INVALIDA );
        break;
        }

    }

    for( j = 0 ; j < i ; j++ )
    {
        s = string[j];

        fin = strrchr( string[j] , '\0' ) - 1;

            while( caracterValido( &s , 1 ) && caracterValido( &fin , -1 ) && tolower(*s) == tolower(*fin) && ( s < fin ) )
            {
                s++;
                fin--;
            }

            if( s >= fin && *s != '\0'  )
                puts( ES_PALINDROMO );
            else
                puts( NO_ES_PALINDROMO );
    }

}

int caracterValido( char ** s , int i )
{
    while ( (tolower(**s) >= 'a' && **s <= 'z') || **s == '.' || **s == ',' || **s == '!' || **s == '?' || **s == ' ')
    {
        if( !(tolower(**s) >= 'a' && **s <= 'z') )
            *s += i;
        else
        return 1;

    }

    return 0;

}


Re: 10945 - Mother Bear WA why? Anyone help me please

Posted: Sun Oct 07, 2012 7:46 pm
by brianfry713
This isn't printing anything. Don't use fflush(stdin). main should return 0 on completion.