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

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sat Dec 10, 2005 3:51 pm

jjtse wrote:does anyone know what was wrong with watershed's code?
I don't know. He hasn't replied any more.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sat Dec 10, 2005 4:53 pm

smilitude wrote:code edited....
now what's wrong?

here it checks every single new word, whether they are really new or not
Are you sure it gives RE? It looks like it should give WA. You write an empty string to the output if the input begins with a non-alpha character.

jjtse
Learning poster
Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:

Post by jjtse » Sat Dec 10, 2005 11:26 pm

Thanks, you are correct from the other topic. I fixed it and got AC. Thanks

jjtse
Learning poster
Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:

Post by jjtse » Sat Dec 10, 2005 11:26 pm

Thanks. I got AC.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sat Dec 10, 2005 11:31 pm

jjtse wrote:Thanks. I got AC.
After you got accepted, please, remove the code to make the topic more readable and not to create unnecessary spoilers.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sun Dec 11, 2005 1:09 pm

roticv wrote:I did according to what was mentioned above, but I still keep getting WA.
code wrote:................pch = strtok(str," :\\;,./\n\t\'"`~!@#$%^&*-_+=1234567890");
Are you sure these are all delimiters that are in the input?

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Fri Jan 13, 2006 7:44 am

Martin Macko wrote:
smilitude wrote:code edited....
now what's wrong?

here it checks every single new word, whether they are really new or not
Are you sure it gives RE? It looks like it should give WA. You write an empty string to the output if the input begins with a non-alpha character.
i think i wrote this ---

Code: Select all

if(words[i][0]!=' ') 
            printf("%s\n",words[i]);
are you sure martin macko?
fahim
#include <smile.h>

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Fri Jan 13, 2006 7:48 am

sorry, it gives output limit exceeded now.
what shd i do?
fahim
#include <smile.h>

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman » Fri Jan 13, 2006 10:42 pm

That means your program somehow manages to get into an infinite loop which I think not very unlikely in this input format. :roll:
You can try my peculiar input strategy for this one.

Code: Select all

scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);
while(scanf(" %[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf)==1)
{
    //process
    scanf(" %[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",buf);

}
You should never take more than you give in the circle of life.

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude » Fri Jan 20, 2006 8:42 am

i was so annoyed with this prob so i finally solved this using hashing.
thanks mahmud bhai and sunny!
fahim
#include <smile.h>

qazxcvbn
New poster
Posts: 3
Joined: Mon Feb 06, 2006 6:41 am

10815 RTE help me!!

Post by qazxcvbn » Mon Feb 06, 2006 6:45 am

Code: Select all

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

using namespace std;

struct tree
{
	tree();
	tree* left;
	tree* right;
	char* content;
};
tree::tree()
{
	left=NULL;
	right=NULL;
	content=NULL;
}
void build(tree* bitree,char *str,int *count);
void post(tree *bitree);
int main()
{
	char str[200];
	char *temp=NULL;
	tree root;
	int i;
	int countword=0;
	while(countword<5000&&scanf("%s",str)==1)
	{
		for(i=0;str[i];i++)
		{
			if('A'<=str[i]&&str[i]<='Z')
			{
				str[i]=tolower(str[i]);
			}
			else if(!('a'<=str[i]&&str[i]<='z'))
			{
				str[i]=' ';
			}
		}
		temp=strtok(str," ");
		while(temp!=NULL)
		{
			build(&root,temp,&countword);
			temp=strtok(NULL," ");			
		}
		temp=NULL;
	}
	post(&root);
	return 0;
}
void build(tree* bitree,char *str,int *count)
{
	if(bitree->content==NULL)
	{
		bitree->content=new char [strlen(str)];
		(*count)++;
		strcpy(bitree->content,str);
	}
	else if(strcmp(bitree->content,str)<0)
	{
		if(bitree->left==NULL)
		{
			bitree->left=new tree;
		}
		build(bitree->left,str,count);
	}
	else if(strcmp(bitree->content,str)>0)
	{
		if(bitree->right==NULL)
		{
			bitree->right=new tree;
		}
		build(bitree->right,str,count);
	}
	return;
}
void post(tree *bitree)
{
	if(bitree->right!=NULL)
	{
		post(bitree->right);
	}
	cout<<bitree->content<<endl;
	if(bitree->left!=NULL)
	{
		post(bitree->left);
	}
	return;
}

I don't know what ERROR in it.Please help me.Thanks.

Staryin
New poster
Posts: 12
Joined: Fri Dec 16, 2005 4:22 pm
Location: shanghai/china
Contact:

10815 WHY CE???????!!!!! CRAZY!!!!!!!1

Post by Staryin » Thu Aug 17, 2006 10:40 am

Code: Select all

#include <iostream>
#include <string>
#include <map>
#include <ctype.h>
#include <cstdlib>

using namespace std;

map<string,int> dict;
map<string,int>::iterator itr;


int main()
{
   string in;
   while(cin>>in)
   {
      string temp;
      temp.clear();
      
      for(int i = 0; i < in.size();i++)
         {

            temp +=(char)tolower(in[i]);
            if(!isalpha(temp[i]))temp[i] = ' ';
         }
      in.clear();
      for(int i = 0; i < temp.size();i++)
         if(isalpha(temp[i]))in+=(char)temp[i];

      dict[in] = 1;
   }
   for(itr = dict.begin();itr!=dict.end();itr++)
     cout<<itr->first<<endl;

   return 0;
}

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10815 WHY CE???????!!!!! CRAZY!!!!!!!1

Post by Martin Macko » Thu Aug 17, 2006 3:08 pm

I've just replied you in the other thread you created. (btw, please, never create two or more threads on the same problem.)

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

Post by kolpobilashi » Wed Nov 22, 2006 9:13 pm

checked all previous posts and the code seems ok, but it gives WA. would anyone kindly hav a look... :(

Code: Select all

cut..
btw, i never used set, thats why i use map here...but it seems ok :roll:
thanx in advance.
Last edited by kolpobilashi on Thu Nov 23, 2006 7:29 pm, edited 1 time in total.
Sanjana

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post by asif_rahman0 » Wed Nov 22, 2006 9:58 pm

You missed the problem statement!!!

Code: Select all

sorted in alphabetical order
So add the following line to sort in map<const char *s,int,cmm>

Code: Select all

struct cmm{
	bool operator()(const char *str1,const char *str2) const
	{
		return strcmp(str1,str2)<0;	
	}
};
btw, how did you check all posts? Even have you checked Sample I/O!!!

Post Reply

Return to “Volume 108 (10800-10899)”