Page 2 of 2

run time error

Posted: Sun Oct 14, 2007 12:52 pm
by rudy yulianto
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...

Posted: Wed Oct 17, 2007 10:29 pm
by Jan
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 '#'.

Re: 895 - Word Problem

Posted: Sat Jul 18, 2009 5:48 am
by Jehad Uddin
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.

Re: 895 - Word Problem

Posted: Wed Nov 10, 2010 5:27 pm
by Shafaet_du
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

Re: 895 - Word Problem

Posted: Sat Dec 11, 2010 6:57 am
by receme
Solved a moment ago :) ...I used LCS. It takes 0.020 sec.

Re:

Posted: Thu Oct 03, 2013 9:50 am
by 20717TZ
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

Re: 895 - Word Problem

Posted: Thu Oct 03, 2013 9:56 am
by 20717TZ
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.

Re: 895 - Word Problem

Posted: Thu Oct 03, 2013 11:08 pm
by brianfry713
There are repeated words in the judge's input, and they should be counted multiple times in the output.

Re: 895 - Word Problem

Posted: Tue Mar 18, 2014 1:44 pm
by uDebug
Replying to follow the thread.