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

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

Re: 10815 - Andy's First Dictionary

Post by brianfry713 »

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!
PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: 10815 - Andy's First Dictionary

Post by PromeNabid »

I got WA. Please help to find my mistake. My idea is:
  • get a line using fgets until EOF
  • check Capital letters, make them small letters
  • tokenize string using strtok() by " 0123456789!@#$%^&*\()_+=-[]{}|\\:;\"\'<,>./?`~" and insert into a map as key(because it sorts itself)
  • finally print the map keys

Code: Select all

code removed
Thanks in advance.
Update: Accepted. Hint: Considering what we need is importent because we don't know what should appear in text.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10815 - Andy's First Dictionary

Post by uDebug »

PromeNabid wrote:Update: Accepted. Hint: Considering what we need is importent because we don't know what should appear in text.
Congrats on figuring this out by yourself!
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
Ahmad93
New poster
Posts: 6
Joined: Wed Mar 05, 2014 6:39 pm

Re: 10815 - Andy's First Dictionary

Post by Ahmad93 »

What's wrong with my code? I am getting wrong answer. :oops:

Code: Select all

 Code removed after AC

Last edited by Ahmad93 on Sat Jul 26, 2014 1:27 am, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10815 - Andy's First Dictionary

Post by lighted »

For this input

Code: Select all

Advanced search 
Accepted.
Thanks in advance.
Your output

Code: Select all

accepted
advanced
in
search
thanks
Acc output

Code: Select all

accepted
advance
advanced
in
search
thanks
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Ahmad93
New poster
Posts: 6
Joined: Wed Mar 05, 2014 6:39 pm

Re: 10815 - Andy's First Dictionary

Post by Ahmad93 »

What a foolish of me! That unnecessary 'return 100' in my strcmp is giving me successive wrong answers!
Thanks a lot to you lighted.:D
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10815 - Andy's First Dictionary

Post by Shahidul.CSE »

I am getting RTE. Whats wrong with my code?

Code: Select all

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

int main()
{
    int len, i, j,c=0;
    char txt[202], word[5002][202], temp[202];
    while(scanf("%s",&txt)!=EOF)
    {
        len=strlen(txt);
        j=0;
        for(i=0;i<len;i++)
        {
            if(txt[i]>='a' && txt[i]<='z')
                temp[j++]=txt[i];
            else if(txt[i]>='A' && txt[i]<='Z')
                temp[j++]=txt[i]-'A'+'a';
        }
        temp[j]='\0';
        if(strlen(temp)>0)
        {
            strcpy(word[c], temp);
            c++;
        }
    }
    for(i=0;i<c;i++)
    {
        for(j=0;j<c-1;j++)
        {
            if(strcmp(word[j], word[j+1])>0)
            {
                strcpy(temp, word[j]);
                strcpy(word[j], word[j+1]);
                strcpy(word[j+1], temp);

            }
        }
    }
    for(i=0;i<c;i++)
        puts(word[i]);
    return 0;
}
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10815 - Andy's First Dictionary

Post by brianfry713 »

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10815 - Andy's First Dictionary

Post by Shahidul.CSE »

My code works fine for the given sample input in problem.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10815 - Andy's First Dictionary

Post by lighted »

Your code prints repeated words. http://ideone.com/N1wbfo
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10815 - Andy's First Dictionary

Post by lighted »

The input file is a text with no more than 5000 lines... You can be sure that he number of distinct words in the text does not exceed 5000
Input file will contain up to 5000 lines, not 5000 words. Words are repeated and number of distinct words <= 5000. So you get RE. I used array for 30000 words. :)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10815 - Andy's First Dictionary

Post by Shahidul.CSE »

what will be the maximum size of a distinct word?
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Post Reply

Return to “Volume 108 (10800-10899)”