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

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: Getting WA in 10815 - Andy's First Dictionary

Post by alimbubt » Mon Dec 17, 2012 6:05 am

Getting WA.....please help me....Is my input process is correct??

Code: Select all

Cut After Accepted
Last edited by alimbubt on Sun Mar 17, 2013 10:40 am, edited 1 time in total.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

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

Re: Getting WA in 10815 - Andy's First Dictionary

Post by brianfry713 » Tue Dec 18, 2012 12:17 am

There may be more than 27 words. You may be modifying s[-1]. You could use a set instead of a map.
Check input and AC output for thousands of problems on uDebug!

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh
Contact:

Re: Getting WA in 10815 - Andy's First Dictionary

Post by alimbubt » Tue Dec 18, 2012 10:08 am

Code: Select all

Cut After Accepted
Last edited by alimbubt on Sun Mar 17, 2013 10:40 am, edited 1 time in total.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

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

Re: Getting WA in 10815 - Andy's First Dictionary

Post by brianfry713 » Wed Dec 19, 2012 12:46 am

input:

Code: Select all

don't
AC output:

Code: Select all

don
t
Check input and AC output for thousands of problems on uDebug!

sun_kuet
New poster
Posts: 12
Joined: Wed Mar 27, 2013 4:28 pm

10815--getting WA

Post by sun_kuet » Fri Jun 14, 2013 10:54 am

Thanks GURU
I removed the code after accepted
Last edited by sun_kuet on Sun Jun 16, 2013 12:28 am, edited 1 time in total.

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

Re: 10815--getting WA

Post by brianfry713 » Fri Jun 14, 2013 10:36 pm

Don't add the null char to a c++ string.
Check input and AC output for thousands of problems on uDebug!

Halah
New poster
Posts: 4
Joined: Mon Jul 22, 2013 3:24 pm

Re: 10815 - Andy's First Dictionary

Post by Halah » Mon Jul 22, 2013 3:37 pm

Hello,, Good Afternoon :)

I got WA too for this problem .. I think the wrong with the space in the beginning of my output
but I couldn't change my code more to avoid this error.. how I can prevent my code to print this space in the beginning of my output!!

Code: Select all


import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        StringBuilder sb = new StringBuilder();
        Set<String> orderedSet = new TreeSet<String>();
        String s = br.readLine();

        while (s != null)
        {
            s = s.toLowerCase();
            String[] list = s.split(" "); 
            
            String word;
            String w, sp;
            
            boolean r = false;

            for (int i = 0; i < list.length; i++) {
                word = sp = "";
                w = list[i];
                for (int j = 0; j < list[i].length(); j++) {
                    
                    if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
                    {
                        r = true;
                        word += w.charAt(j);
                        
                    }
                    else if(w.charAt(j) == '\'')
                    {
                        for (int k = ++j; k < list[i].length(); k++) {
                            sp += w.charAt(k);
                        }
                        
                        orderedSet.add(sp);
                        break;
                    }

                }
                if(r)
                    orderedSet.add(word);
                
            }

            s = br.readLine();
            
        }
        
        for (String i: orderedSet) {
                sb.append(i +"\n");
        }
        sb.deleteCharAt(sb.length()-1);
        System.out.println(sb);     
    }
}

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 » Tue Jul 23, 2013 1:18 am

brianfry713 wrote:For an input file containing:

Code: Select all

a\bc
My AC output is:

Code: Select all

a
bc
I used the c function isalpha().
Check input and AC output for thousands of problems on uDebug!

Halah
New poster
Posts: 4
Joined: Mon Jul 22, 2013 3:24 pm

Re: 10815 - Andy's First Dictionary

Post by Halah » Tue Jul 23, 2013 3:00 pm

Thank you brianfry713 for your reply .. I corrected my code but uva still gives me WA!!
what is the wrong?

My updated code:

Code: Select all

import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

        StringBuilder sb = new StringBuilder();
        Set<String> orderedSet = new TreeSet<String>();
        String s = br.readLine();
        String word;
        String w, sp;
            

        while (s != null)
        {
            s = s.toLowerCase();
            String[] list = s.split(" "); 

            for (int i = 0; i < list.length; i++) {
                word = ""; sp = "";
                w = list[i];  
                boolean r1 = false;
                boolean r2 = true;
                for (int j = 0; j < w.length(); j++) {
                    
                    if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
                    {
                        r1 = true;
                        word += w.charAt(j);
                        
                    } 
                    else
                    {
                        for (int k = ++j; k < list[i].length(); k++) {
                            if ((w.charAt(j) >= 'a' && w.charAt(j) <= 'z'))
                                r2= false;
                                sp += w.charAt(k);
                        }
                        if(!r2)
                            orderedSet.add(sp);
                        break;
                       
                    }

                }

                if(r1)
                  orderedSet.add(word);
                
            }

            s = br.readLine();
            
        }
        for (String i: orderedSet) {
             sb.append(i +"\n");
        }
        sb.deleteCharAt(sb.length()-1);
        System.out.println(sb);     
    }
}


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 » Wed Jul 24, 2013 11:49 am

Try input:
a1b1c
Output should be:
a
b
c
Check input and AC output for thousands of problems on uDebug!

Halah
New poster
Posts: 4
Joined: Mon Jul 22, 2013 3:24 pm

Re: 10815 - Andy's First Dictionary

Post by Halah » Wed Jul 24, 2013 9:57 pm

brianfry713 wrote:Try input:
a1b1c
Output should be:
a
b
c
again WA!!!!!!!!
I gave up .. I will try another problem =)

Thanks for your help :oops:

omar_faruk
New poster
Posts: 1
Joined: Mon Dec 09, 2013 9:06 pm

Re: 10815 - Andy's First Dictionary

Post by omar_faruk » Mon Dec 09, 2013 9:13 pm

getting wrong answer please help..
my code: http://ideone.com/TiCxI1

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 » Wed Dec 11, 2013 12:33 am

Don't use scanf("%[^EOF]",s);
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10815 - Andy's First Dictionary

Post by uDebug » Fri Jan 10, 2014 8:25 am

Here's some input / output that helped me during testing / debugging.

Input:

Code: Select all

a\bc 1111111111x2222y1:""z,..,. e{g|f ThIsAWord222?#&*()! 
andy's--> 
~`cd()f:
;f^g9009?? /hijklmnop   
q r s
<<<<<z>>>>>
9u)v(w**%x#y
AC Output:

Code: Select all

a
andy
bc
cd
e
f
g
hijklmnop
q
r
s
thisaword
u
v
w
x
y
z
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

raihan_sust05
New poster
Posts: 5
Joined: Fri Nov 22, 2013 6:34 pm

WA: 10815 - Andy's First Dictionary

Post by raihan_sust05 » Wed Apr 09, 2014 9:25 pm

Getting WA!! :roll:
please anyone help

Code: Select all

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>


#define pi acos(0)
#define inf 1<<30
#define max 10000
#define sz 5000
#define true 1
#define false 0
#define pb(a) push_back(a)
#define size(e) (int)e.size()
#define clr(a,b) memset(a,b,sizeof(a))

typedef long long int ll;

using namespace std;

set <string> S;

int main()
{
    char bin[sz];
    string tmp;
    while(gets(bin))
    {
//        getchar();
        int strln = strlen(bin);

        int i = 0;
        for(int j = 0; j <  strln; ++j)
            bin[j] = tolower(bin[j]);
        while(i < strln)
        {
            while(bin[i] >= 'a' && bin[i] <= 'z')
            {
                tmp.pb(bin[i]);
                ++i;
            }
            S.insert(tmp);
            tmp.clear();
            ++i;
        }
    }
    set <string> :: iterator sit;
    for(sit = S.begin(); sit != S.end(); ++sit)
        cout << *sit << endl;
    return 0;
}

Post Reply

Return to “Volume 108 (10800-10899)”