895 - Word Problem

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

Moderator: Board moderators

rudy yulianto
New poster
Posts: 4
Joined: Sun Sep 09, 2007 1:42 pm
Location: Indonesia
Contact:

run time error

Post by rudy yulianto » Sun Oct 14, 2007 12:52 pm

i have been try some input from Jan
abc
bcd
cde
def
eee
eff
eggg
ffff
#
e e e
#
and my output
  • 1
but my submission is run time error

it's my code in C

Code: Select all

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

int counter[1232];
int main()
{
	int flag;
	char dic[1233][13];
	char puzzle[1234][13];
	int i =-1,j=-1;

	int a,b,len,c;
	char buff[13];
	int k;
	do
	{
		i++;
		gets(dic[i]);
	}while(dic[i][0]!='#');
	j=-1;
	do
	{
		j++;
		gets(puzzle[j]);
	}while(puzzle[j][0]!= '#');

	for(a=0;a<j;a++)
	{
		for(b=0;b<i;b++)
		{
			strcpy(buff,puzzle[a]);
			for(c=0;c<strlen(dic[b]);c++)
			{
				flag=1;
				for(k=0;k<strlen(buff);k++)
				{
					if(dic[b][c] != buff[k])
						flag=0;

					else
					{
						flag=1;
						buff[k]=' ';
						break;
					}
				}
				if(flag==0)break;
			}
			if(flag==1) counter[a]++;

		}
    	printf("%d\n",counter[a]);
	}


	return 0;
}
please help me, give some reason why RTE and give me some IO..thx before...
sorry my english is bad

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Oct 17, 2007 10:29 pm

How did you know that there are less than 1234 word puzzles? The problem states that the dictionary can have at most 1000 words. But there is no restriction for the number of word puzzles. So, just pick a puzzle, solve it and print the result until you get the '#'.
Ami ekhono shopno dekhi...
HomePage

Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 895 - Word Problem

Post by Jehad Uddin » Sat Jul 18, 2009 5:48 am

Hello every body,i am getting frustrated with the problem.Though i passed all the I/Os from the board.Here is my code.Pls help me.

Code: Select all

#include<iostream>
#include<string>
using namespace std;
int main()
{
 char dic[1002][20];
 long int a[1002][27];
 long int word[27];
 long int i,j,k,l,m;
 char str[20];
 while(cin>>dic[0])
 {
  for(i=0;i<26;i++) a[0][i]=0;
	 for(i=0;i<strlen(dic[0]);i++)
	  a[0][dic[0][i]-97]++;
  k=1;
  while(1)
  {
   cin>>dic[k];
   if(strcmp(dic[k],"#")==0) break;
   for(i=0;i<26;i++) a[k][i]=0;
   for(i=0;i<strlen(dic[k]);i++)
	  a[k][dic[k][i]-97]++;
   k++;
  
  }
  getchar();
  while(1)
  {
   gets(str);
   if(str[0]=='#') break;
   for(i=0;i<26;i++)
	   word[i]=0;
   for(i=0;i<strlen(str);i++)
	 if(str[i]>=97&&str[i]<=122)  word[str[i]-97]++;
   m=0;l=1;
   for(i=0;i<k;i++)
   {
    for(j=0,l=1;j<26;j++)
    if(word[j]<a[i][j])
	{
	 l=0;
	 break;
	}
   
    if(l) m++;
   }
  
  cout<<m<<endl;
  
  }
 
 
 
 }

 return 0;
}
Advanced thanks for the helpers.

Shafaet_du
Experienced poster
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh
Contact:

Re: 895 - Word Problem

Post by Shafaet_du » Wed Nov 10, 2010 5:27 pm

sample

Code: Select all

hello
this
hiso
csedu
dhaka
niceprob
rivers
cricket
acm
acm
this
string
c
you
#
a c c c h i m
s r w d d g d
h s a i o c m
c a q r t r r
h l l y o o u
#
output:

Code: Select all

3
0
4
1
1

receme
New poster
Posts: 17
Joined: Thu Jul 01, 2010 11:55 am

Re: 895 - Word Problem

Post by receme » Sat Dec 11, 2010 6:57 am

Solved a moment ago :) ...I used LCS. It takes 0.020 sec.

20717TZ
New poster
Posts: 33
Joined: Tue Apr 27, 2004 7:41 pm
Location: Santa Clara / Mountain View, CA, USA
Contact:

Re:

Post by 20717TZ » Thu Oct 03, 2013 9:50 am

sohel wrote:
Do you consider the case that same word may appear more than once
in the dictionary ?
You mean the dictionary can contain the same word twice.

For example :

cat
cat
dog
lion
#
c a t
#

will output 2.

I applied the method that .. mentioned and got AC.. but still can't figure out why the original was rejected.
WOW, I used a "std::map<string, map<char, int> >" to intentionally handle the case that same word appears twice in the dictionary, and I don't think it should output 2, because in the problem description, it states very clearly:
For each puzzle line in the input, a single line of output should be produced, containing the number of different words in the dictionary that can be formed using the letters in the puzzle line.
And I got a "Wrong Answer" verdict.

My code runs with the following input:

Code: Select all

ant
bee
cat
dog
ewe
fly
gnu
abcdefgh
abcdefghij
x
x
xxx
y
z
#
b e w
b b e e w w
t a n c u g d
x
x y
x y z
x x x
#
giving the output:

Code: Select all

0
2
3
1
2
3
2
I Believe I Can - leestime.com

20717TZ
New poster
Posts: 33
Joined: Tue Apr 27, 2004 7:41 pm
Location: Santa Clara / Mountain View, CA, USA
Contact:

Re: 895 - Word Problem

Post by 20717TZ » Thu Oct 03, 2013 9:56 am

Shafaet_du wrote:sample

Code: Select all

hello
this
hiso
csedu
dhaka
niceprob
rivers
cricket
acm
acm
this
string
c
you
#
a c c c h i m
s r w d d g d
h s a i o c m
c a q r t r r
h l l y o o u
#
output:

Code: Select all

3
0
4
1
1
I think it should be:

Code: Select all

2
0
3
1
1
Because in the problem description, it states very clearly:
For each puzzle line in the input, a single line of output should be produced, containing the number of DIFFERENT words in the dictionary that can be formed using the letters in the puzzle line.
But I got a "Wrong Answer" verdict.
I Believe I Can - leestime.com

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 895 - Word Problem

Post by brianfry713 » Thu Oct 03, 2013 11:08 pm

There are repeated words in the judge's input, and they should be counted multiple times in the output.
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 895 - Word Problem

Post by uDebug » Tue Mar 18, 2014 1:44 pm

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 8 (800-899)”