409 - Excuses, Excuses!

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

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 »

Input:

Code: Select all

1 2
dog
dog0dog
dog
AC output:

Code: Select all

Excuse Set #1
dog0dog

Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 409 - Excuses, Excuses!

Post by brianfry713 »

Input:

Code: Select all

1 2
dog
dog?dog
dog
AC output:

Code: Select all

Excuse Set #1
dog?dog

Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 409 - Excuses, Excuses!

Post by brianfry713 »

Input:

Code: Select all

1 2
dog
dog"dog
dog
AC output:

Code: Select all

Excuse Set #1
dog"dog

Check input and AC output for thousands of problems on uDebug!
saniatrasel
New poster
Posts: 5
Joined: Tue Apr 07, 2015 11:10 am

Re: 409 - Excuses, Excuses!

Post 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;
}
Post Reply

Return to “Volume 4 (400-499)”