10815 - Andy's First Dictionary

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

Moderator: Board moderators

kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:

Post by kolpobilashi » Thu Nov 23, 2006 7:27 pm

map is a sorted container.so my problem was not this.the mistake was here
your program must be CaSe InSeNsItIvE
i fixed it and got AC.
thanx anyway. :D
Sanjana

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Post by alamgir kabir » Wed Oct 31, 2007 3:39 pm

.
Last edited by alamgir kabir on Thu Nov 01, 2007 1:02 pm, edited 1 time in total.

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil » Thu Nov 01, 2007 4:32 am

To alamgir

Input this case:

Code: Select all

     aaa     a

>> your code given some garbage output


Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil » Thu Nov 01, 2007 4:32 am

To alamgir

Input this case:

Code: Select all

     aaa     a

>> your code given some garbage output


Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

Post by alamgir kabir » Thu Nov 01, 2007 1:01 pm

I have got it Acc

Code: Select all


//code remove

Thank you very much sapnil.

aeiou
New poster
Posts: 21
Joined: Wed May 07, 2008 11:32 am

Re: 10815 - Andy's First Dictionary

Post by aeiou » Mon Jun 30, 2008 9:22 am

Hi ,
Deleted

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 10815 - Andy's First Dictionary

Post by newton » Sun Oct 19, 2008 10:23 pm

Why RE.
please any one check my small code

Code: Select all

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define MAX 5001
using namespace std;

int comp(const void *a, const void *b)
{    
    return strcmp((char *)a,(char *)b);
}

int main(){
	char str[2000],*p;
	char word[MAX][100];
	char dil[] = " .:,\"'";
	int k = 0,i,j;
	//freopen("in.txt","rt",stdin);
	while(scanf("%s",str) == 1){
		p = strtok(str,dil);
		if(p)
			strcpy(word[k++],p);

		while(p){
			p = strtok(NULL,dil);
			if(p)			
				strcpy(word[k++],p);
		}		
	}
	for(i = 0; i<k; i++){
		for(j = 0;word[i][j]; j++){
			word[i][j] = tolower(word[i][j]);
		}
	}
	qsort(word,k,sizeof(word[0]),comp);
	for(i = 1; i < k+1; i++){
		if(strcmp(word[i],word[i-1]))
			printf("%s\n",word[i-1]);
	}
	return 0;
}
advanced thanks

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10815 - Andy's First Dictionary

Post by mf » Mon Oct 20, 2008 1:34 am

char word[MAX][100];
I think words are allowed to be up to 200 characters long by problem's text. And since it seems like you're using C++ anyway, why not just use std::string to keep strings?

Then, the problem text says "You can be sure that he number of distinct words in the text does not exceed 5000." But you're assuming that the *total* number of words is at most 5001, which is wrong.
char dil[] = " .:,\"'";
That's not going to solve the problem.

Stick to definitions, "a word is defined as a consecutive sequence of alphabets".

Marcel Hernandez
New poster
Posts: 7
Joined: Wed Mar 04, 2009 4:00 pm
Location: Barcelona, Spain

Re: 10815 - Andy's First Dictionary

Post by Marcel Hernandez » Wed Sep 23, 2009 2:11 pm

oh hai,

I've already solved the problem (scoring a pitiful run time btw) but I'm always not really sure of what to do when it comes to handle input like the one seen in this problem.


This is some kind of sketch written in C++ showing my approach:

Code: Select all

    string word;
    vector<string> dic;
    char symbol = getchar();
    while (symbol != EOF)
    {    
    	if (isalpha(symbol)) // convert 'symbol' to lowercase if necessary and append it to the end of 
                            // 'word'
    	else // add 'word' to the vector and sort it if 'word' is not in it yet and finally clear the 
            // auxiliary string
    	symbol = getchar(); 		
    }
So I'd just like to know if there are better/easier/simpler ways to read several strings from a line. C code is also welcomed.
If only while (cin>> s) { ... } worked as if they were integers... -_-

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

Re: 10815 - Andy's First Dictionary

Post by Jehad Uddin » Thu Oct 08, 2009 10:11 am

you can use getline or gets

Code: Select all

string str;
while(getline(cin,str,'\n'))
{
 .......then just take words ....
}
char str[300];
while(gets(str))
{
 .......
}

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 10815 - Andy's First Dictionary

Post by sazzadcsedu » Fri May 07, 2010 7:43 pm

Or you can use scanf in following way

Code: Select all


char S[20000][300];
char str[300];
char s[300];
while(scanf("%s",str)==1)
{
	k=0;
	word=0;
	for(i=0;str[i];i++)
	{
			
		if(isalpha(str[i]))
		{
			ch=tolower(str[i]);
			s[k]=ch;
			k++;
			word=1;
		}
		else
		{
			if(word==1)
			{
				s[k]='\0';
				strcpy(S[l],s);
				l++;
				word=0;
				k=0;
			}
		}

	}

	if(word==1)
	{ 
		s[k]='\0';
		strcpy(S[l],s);
		l++;
	}
}

Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

shantanu18
New poster
Posts: 22
Joined: Tue Jul 20, 2010 9:55 pm

Re: 10815 - Andy's First Dictionary

Post by shantanu18 » Sat Sep 04, 2010 7:00 am

I think the following approach is good to take input for this problem. It is difficult to include all punctuation.

Code: Select all

while((getline(cin,st))!=NULL)
{
	strcpy(ch,st.c_str());
	for(int i=0;i<(int)strlen(ch);i++)
	{
		if(!isalpha(ch[i]))
			ch[i]=' ';
		else if(isalpha(ch[i]) && isupper(ch[i])) ch[i]=tolower(ch[i]); //making all lower case
	}
	parse(ch);
}
//parse the char arr using strtok. there are only space char and tab char. Now it is easy to parse 

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 10815 - Andy's First Dictionary

Post by shaon_cse_cu08 » Thu Nov 11, 2010 4:36 pm

Plz Help me I m getting RE....

Code: Select all

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

void ch_sort(char str[5000][201],int n);

int main()
{
	int n=0,i,j,tag=1;

	char a[5000][201],b[5000][201];

	while(gets(a[n++]))


	for(i=0;i<n;i++)
	{
	    for(j=0;a[i][j]!='\0';j++)
		{
			if(a[i][j]>='A'&&a[i][j]<='Z')
				a[i][j]+=32;
		}
	}
	
	int k=0,l;

	for(i=0;i<n;i++)
	{
		l=0;
		tag=0;
	    for(j=0;a[i][j]!='\0';j++)
		{
			if(a[i][j]>='a'&&a[i][j]<='z')
			{
				b[k][l++]=a[i][j];
				tag=1;
			}
			else
			{
				if(tag==1)
				{
					b[k][l]='\0';
					k++;
					l=0;
					tag=0;
				}
			}		
		}
		if(tag==1)
		{
			b[k][l]='\0';
			k++;
			l=0;
			tag=0;
		}

	}
	
	ch_sort(b,k);

	for(i=0;i<k;i++)
	{
		if(b[i][0]!='\0')
			puts(b[i]);
	}
		

return 0;
}

void ch_sort(char str[5000][201],int n)
{
	char dummy[201];
	
	int i,j;

	for(i=0;i<n-1;i++)
	{
		for(j=0;j<=n-i-1;j++)
		{
			if(strcmp(str[j],str[j+1])>0)
			{
			
				strcpy(dummy,str[j]);
				strcpy(str[j],str[j+1]);
				strcpy(str[j+1],dummy);
			}
			if(strcmp(str[j],str[j+1])==0)
				str[j+1][0]='\0';
		}
	}

return;
}
Plz plz Help.... :( :cry:
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

Victor Pangaldus
New poster
Posts: 2
Joined: Tue Sep 21, 2010 11:34 pm

Re: 10815 - Andy's First Dictionary

Post by Victor Pangaldus » Mon Nov 22, 2010 1:28 am

Hi all,

I am newbie to Uva online judge. I am stuck on this problem (10815: Andy's First Dictionary) :( . My code give right outputs for the test case I get from the problem and in this forum but I continually get WA for this problem. I do not know what is wrong with my code. Can anyone help me to figure it out by giving me some critical test case?

I am looking forward to hearing from you. Thank you in advanced.

Regards,

Victor Pangaldus

BUET
New poster
Posts: 22
Joined: Sun Jun 13, 2010 8:38 am

10815 - Andy's First Dictionary

Post by BUET » Wed Dec 29, 2010 8:51 am

My accepte program uses these delimiters:

" !\"#$%&'()*+,-./0123456789:;<=>?@[\\]^_`{|}~\t\r\n"

Post Reply

Return to “Volume 108 (10800-10899)”