494 - Kindergarten Counting Game

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

Moderator: Board moderators

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

Getting wrong answer on 494

Post by noor_aub » Sun Aug 23, 2009 6:25 am

I have tried all thing. All creatical input and output set. The answer was correct. But I am getting wrong answer. My code is
#include<iostream>
using namespace std;

int main()
{
//freopen("1.txt","r",stdin);
char c;
int count=0,space=1;
while((c=getchar())!=EOF)
{
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
if(space)
{
count++;
space=0;
}
}
else if(c=='\n'||c=='\r')
{
cout<<count<<endl;
count=0;
space=1;
}
else
space=1;
}
cout<<count<<endl;
return 0;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: Getting wrong answer on 494

Post by mf » Sun Aug 23, 2009 10:39 pm

* Don't post duplicate messages
* Don't start a new thread, do search for an existing thread on problem 494 and post there.
* Read existing replies in that thread before posting.
* Use [code]...[/code] tags to format source code.

* And in case if you need to start a new thread for a problem, which wasn't yet discussed, follow the convention for thread's title: "<Problem's number> - <Problem's title>". No "Gettign W/A on problem" or anything like that.

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

Re: 494 Kinder Garden Counting Game WA

Post by noor_aub » Sun Oct 11, 2009 7:36 am

If there is two new line what should the program out put 0 or nothing.

fahim_xubayer
New poster
Posts: 5
Joined: Wed Sep 23, 2009 8:57 am

Re: 494 WA

Post by fahim_xubayer » Tue Oct 27, 2009 11:08 pm

getting Wa
can anyone help please?

Code: Select all

#include<stdio.h>
#include<string.h>
int main(){

  unsigned long int a,b,d,x,y,z,l;
  char c,m[50000];
  while(gets(m)){
    l=strlen(m);
    b=0;
    for(a=0;a<l;a++){
      c=m[a];
      if(((c<65)||(c>122))||((c>90)&&(c<97)))
      continue;
      while(((m[a]>65)&&(m[a]<91))||((m[a]>96)&&(m[a]<123))){
        if(m[a]==10)
        break;
      a++;
    }
      b++;
    }

    printf("%lu\n",b);
  }
  return 0;
}

noor_aub
New poster
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

Re: 494 WA

Post by noor_aub » Wed Nov 04, 2009 9:41 am

Every Body who have faced W/A in this problem use isalpha function.

It will be lot easier for you.

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 494 WA

Post by mehrab » Tue Jul 06, 2010 7:16 am

code removed ....
Last edited by mehrab on Tue Jul 13, 2010 1:05 pm, edited 1 time in total.

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 494 WA

Post by mehrab » Tue Jul 06, 2010 7:20 am

1.should the program print 0 for only one letter input?
2.should i print blank line for a blank input or should i print 0?

thnx

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 494 WA

Post by sazzadcsedu » Tue Jul 06, 2010 9:37 pm

Did yo notice that ->
each line containing multiple words (at least one). A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
This means that there is no one letter input(Bcoz it is not a word, A word is defined as a consecutive sequence of letters,And each line containing multiple words (at least one).)

But if you still want to know what is the output of one letter input then i can say my ACC program return 1 for one letter
input.

And your second question is already answered(At least one word in input,no blank line in input).
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 494 WA

Post by mehrab » Thu Jul 08, 2010 9:34 pm

thnx for da reply ...
but hav u seen my code ... what's wrong there why my code is getting WA

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 494 WA

Post by sazzadcsedu » Fri Jul 09, 2010 9:21 am

I think ur tab character does not work correctly.For input
ab<tab>cd<tab>ef

your output produce 1 ,which should be 3.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 494 WA

Post by mehrab » Tue Jul 13, 2010 11:14 am

i'm using visual c++ compiler and it is producing correct answer for your input...
does it cause any problem for using two different compilers??

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 494 WA

Post by sazzadcsedu » Tue Jul 13, 2010 8:55 pm

I am also using visual c++ compiler , But in my compiler
ab<tab>cd<tab>ef

your output produce 1 ,which should be 3.
And your code is no longer in board.So i cant test it again.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

494 test my code. why WA?

Post by @mjad » Thu Oct 28, 2010 6:53 am

why wrong answer? please help me

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>

#define M 1000000
int main()
{
	//freopen ("494.txt","r",stdin);
	char text[M],*t;

	int f,i,count,tem;
	while(gets(text))
	{
		count=0;
		t=strtok(text," !.,;~!@#$%^&*()\t_\?/\n");
		while(t)
		{
			f=0;
			tem=strlen(t);
			for(i=0;i<tem;i++)
				if(t[i]>='A'&&t[i]<='Z'||t[i]>='a'&&t[i]<='z')
				{
					f=1;
					break;
				}
			 
			if(f)
				count++;
			t=strtok(NULL," !.,;~!@#$%^&*()\t_\?/\n");
		}
		printf("%d\n",count);
	}
	
	return 0;
}

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 494 WA

Post by sazzadcsedu » Wed Nov 03, 2010 7:45 pm

Ok,tell me what will be the output of

Code: Select all

salim1233sazzad
your code produce 1.And the correct answer is 2.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

Re: 494 WA

Post by @mjad » Thu Nov 04, 2010 3:49 am

:D Thanks for your reply , i got AC :D

Post Reply

Return to “Volume 4 (400-499)”