Page 5 of 5

Re: 409 - Excuses, Excuses!

Posted: Sun Dec 21, 2014 2:58 am
by brianfry713
Input:

Code: Select all

1 2
dog
dog0dog
dog
AC output:

Code: Select all

Excuse Set #1
dog0dog


Re: 409 - Excuses, Excuses!

Posted: Sun Dec 21, 2014 8:08 pm
by brianfry713
Input:

Code: Select all

1 2
dog
dog?dog
dog
AC output:

Code: Select all

Excuse Set #1
dog?dog


Re: 409 - Excuses, Excuses!

Posted: Mon Dec 22, 2014 2:29 am
by brianfry713
Input:

Code: Select all

1 2
dog
dog"dog
dog
AC output:

Code: Select all

Excuse Set #1
dog"dog


Re: 409 - Excuses, Excuses!

Posted: Thu Apr 30, 2015 1:45 pm
by saniatrasel
I got runtime error. Though its successfully return correct result of all sample input from UVA debug. Can you anyone help me where did I make mistake exactly:

Code: Select all

#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
	int tc = 1;
	int K,E;
	int testCase = 1;

	while((scanf("%d%d",&K,&E))!=EOF)
	{
		if((K==0) && (E==0))
			break;
		int i,j,k=0;		
		char *excuse[20];
		char *keyWords[20];	
		char *statements[20];
		int matchword[100] = {0};
		int len,count = 0;
		int max = 1;
		
		for(i=0;i<K;i++)
		{			
			char str[1000] = {'\0'};
			scanf("%s",str);	
			len = strlen(str);			
			keyWords[i]=(char *)malloc(sizeof(char)*(len+1)); 
			strcpy(keyWords[i],str);
		}
		for(i=0;i<E;i++)
		{				
			char ch;
			char str[1000] = {'\0'};
			char sentence[1000] = {'\0'};
			if(i==0)
			{
				getchar();		
			}
			int c = 0;			
			int st = 0;
			while((ch=getchar())!='\n')
			{
				
				if((isalpha(ch))||(ch==' '))
				{
					str[c] = tolower(ch);
					c++;
				}
				sentence[st] = ch;
				st++;
			}
			str[c] = '\0';
			
			len = strlen(str);			
			excuse[i]=(char *)malloc(sizeof(char)*(len+1)); 
			strcpy(excuse[i],str);

			sentence[st] = '\0';
			len = strlen(sentence);			
			statements[i]=(char *)malloc(sizeof(char)*(len+1)); 
			strcpy(statements[i],sentence);		
			
		}
		int previousmax = 1;
		for(i=0;i<E;i++)
		{
			for(j=0;j<K;j++)
			{
				if(strstr(excuse[i],keyWords[j])!=NULL)					
					count++;
			}
			if(count>=max)
			{
				max = count;
				if(previousmax<max)
				{
					if(k>0)
						k--;
				}
				matchword[k] = i;
				previousmax = max;
				k++;
			}
			count = 0;
		}
		printf("Excuse Set #%d\n",testCase);
		for(i=0;i<k;i++)
		{
			printf("%s\n",statements[matchword[i]]);			
		}
		printf("\n");
		testCase++;

		for(i=0;i<K;i++)
		{
		free(keyWords[i]);
		}
		for(i=0;i<E;i++)
		{
		free(statements[i]);
		free(excuse[i]);
		}
	}	
	return 0;
}