Page 3 of 8

10815 - Andy's First Dictionary

Posted: Thu Jun 16, 2005 5:50 pm
by Sanny
Problem description says that number of distinct words will be less than 5000. But you're assuming total number of words to be less than 5000.

10815 wrong

Posted: Sun Jul 17, 2005 4:03 pm
by watershed
Who can help me solve this problem, thanks~

Code: Select all

using namespace std;
	set<string> words;
	string buffer="", word="";
	while( cin >> buffer ) {
		int len = buffer.length();
		for(int i=0; i<=len; ++i) {
			if( buffer[i] >= 'A' && buffer[i] <= 'Z' )
			else if( buffer[i] >= 'a' && buffer[i] <= 'z' )
			else if( word != "" ) {
	set<string>::iterator p;
	for(p=words.begin(); p!=words.end(); ++p)
		cout << *p << endl;

Re: 10815 wrong

Posted: Fri Jul 29, 2005 7:51 am
by Martin Macko
watershed wrote:

Code: Select all

		int len = buffer.length();
		for(int i=0; i<=len; ++i) {
Shouldn't it be i < len ?

I got WA too :'(

Posted: Sun Jul 31, 2005 3:07 am
by FAQ

Code: Select all


Re: I got WA too :'(

Posted: Sun Jul 31, 2005 4:17 pm
by Martin Macko
Have you tried any really huge input? What about 5000 random words of length something about 200 chars?

Posted: Sun Jul 31, 2005 5:12 pm
by FAQ
Yes, I have tried an input with 5000 lines, and string[200] 'aaaaa..a' for each line, and it runs well

Posted: Mon Aug 01, 2005 6:48 am
by Martin Macko
FAQ wrote:Yes, I have tried an input with 5000 lines, and string[200] 'aaaaa..a' for each line, and it runs well
Just try random strings. But do not forget to check you are not using more that 32MB ram, eg. by ulimit if you are using linux.

Limits. Re: I got WA too :'(

Posted: Thu Aug 04, 2005 11:41 pm
by _.B._
Greetings FAQ!
For this problem I considered all words to be <= than 200 chars long, and no more than 50000 words in Andy's Dictionary (maybe a lot less than that would work).
Quick Sort did the work, and just don't print the repeated words.
Remember all words must be lowercase.
Ah!, and either tokenize lines, or build words char-by-char.

Hope it helps.

ACed :)

Posted: Sun Aug 14, 2005 4:04 pm
by FAQ
Thanks a lot Martin, _.B._. I got AC now


Posted: Fri Oct 07, 2005 7:27 pm
by smilitude

runtime error!

Code: Select all

10815 - andy's first dictionary
submission 1 runtime error!  2 output limit exceeded!
coded at 4:42 on 6th oct 05

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

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

int main() {
	char line[205];
	char words[5005][205];
	char current_word[205];
	int i,j,len,k;
	int total=0;

	//input taking 
	while(gets(line)!=NULL) {
	//choosing word - lowering and then saving them
		for(i=0;i<len;i++) {
			while(isalpha(line[i])) {


	//sorting the whole dictionary

	//output routine
		for(i=1;i<total;i++) {
			//if(strcmp(words[i]," "));			
           if(words[i][0]!=' ')
		return 0;

Posted: Tue Oct 11, 2005 11:53 pm
by sunny
i didn't read your code fully. in this problem you should make your arraysize for the words much bigger. There are 5000 distinct words. but
more than 5000 words which are same to any others. one other thing you should declare large arrays globally unless there's a chance for RTE.

Posted: Wed Oct 12, 2005 2:46 am
by smilitude
code edited....
now what's wrong?

here it checks every single new word, whether they are really new or not

10815 Presentation Error (PE)

Posted: Fri Dec 09, 2005 11:54 pm
by jjtse
Hey fellas,

I've been working on this problem for a while now. Finally got it to work correctly. The only problem now is that it's getting a presentation error. I bet it's something trivial, it's just that I can't see it. I tried putting/removing the newline at the end of the output file. That didn't make a difference. Can someone run this on their machine with the correct version of the compiler and let me know where I presented my data wrong? Thanks. This is what I have:

Code: Select all

code removed...

Posted: Sat Dec 10, 2005 9:21 am
by jjtse
does anyone know what was wrong with watershed's code? Apparently, I'm having the same problem he used to have. I compared the output produce by my codes with the output produced by his codes, and it looks exactly the same. Mine, however, has presentation error instead of wrong answer, and I can't see where I'm presenting it wrong.

Re: 10815 Presentation Error (PE)

Posted: Sat Dec 10, 2005 3:48 pm
by Martin Macko
jjtse wrote:

Code: Select all

  while (!cin.eof()){
    s = "";
    while (isalpha(c)){
      if (cin.eof())
If the input begins with a non-alpha character your output contains the empty word "".