Page 5 of 8

Posted: Thu Nov 23, 2006 7:27 pm
by kolpobilashi
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

Posted: Wed Oct 31, 2007 3:39 pm
by alamgir kabir
.

Posted: Thu Nov 01, 2007 4:32 am
by sapnil
To alamgir

Input this case:

Code: Select all

     aaa     a

>> your code given some garbage output


Thanks
Keep posting
Sapnil

Posted: Thu Nov 01, 2007 4:32 am
by sapnil
To alamgir

Input this case:

Code: Select all

     aaa     a

>> your code given some garbage output


Thanks
Keep posting
Sapnil

Posted: Thu Nov 01, 2007 1:01 pm
by alamgir kabir
I have got it Acc

Code: Select all


//code remove

Thank you very much sapnil.

Re: 10815 - Andy's First Dictionary

Posted: Mon Jun 30, 2008 9:22 am
by aeiou
Hi ,
Deleted

Re: 10815 - Andy's First Dictionary

Posted: Sun Oct 19, 2008 10:23 pm
by newton
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

Re: 10815 - Andy's First Dictionary

Posted: Mon Oct 20, 2008 1:34 am
by mf
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".

Re: 10815 - Andy's First Dictionary

Posted: Wed Sep 23, 2009 2:11 pm
by Marcel Hernandez
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... -_-

Re: 10815 - Andy's First Dictionary

Posted: Thu Oct 08, 2009 10:11 am
by Jehad Uddin
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))
{
 .......
}

Re: 10815 - Andy's First Dictionary

Posted: Fri May 07, 2010 7:43 pm
by sazzadcsedu
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++;
	}
}


Re: 10815 - Andy's First Dictionary

Posted: Sat Sep 04, 2010 7:00 am
by shantanu18
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 

Re: 10815 - Andy's First Dictionary

Posted: Thu Nov 11, 2010 4:36 pm
by shaon_cse_cu08
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:

Re: 10815 - Andy's First Dictionary

Posted: Mon Nov 22, 2010 1:28 am
by Victor Pangaldus
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

10815 - Andy's First Dictionary

Posted: Wed Dec 29, 2010 8:51 am
by BUET
My accepte program uses these delimiters:

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