895 - Word Problem

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

Moderator: Board moderators

run time error

Postby 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
rudy yulianto
New poster
 
Posts: 4
Joined: Sun Sep 09, 2007 1:42 pm
Location: Indonesia

Postby 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
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Re: 895 - Word Problem

Postby 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.
Jehad Uddin
Learning poster
 
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 895 - Word Problem

Postby 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
Shafaet_du
Experienced poster
 
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh

Re: 895 - Word Problem

Postby receme » Sat Dec 11, 2010 6:57 am

Solved a moment ago :) ...I used LCS. It takes 0.020 sec.
receme
New poster
 
Posts: 17
Joined: Thu Jul 01, 2010 11:55 am

Previous

Return to Volume VIII

Who is online

Users browsing this forum: No registered users and 1 guest