195 - Anagram

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

elgeish
New poster
Posts: 3
Joined: Mon Mar 01, 2004 12:36 am

195 - OLE

Post by elgeish » Wed Jul 13, 2005 10:42 pm

why OLE?

Code: Select all

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool cmp ( char a, char b ) { return (a|32) == (b|32) ? a >= 'A' && a <= 'Z' : (a|32) < (b|32); }

void main() {
// .... ACC
}
Last edited by elgeish on Sun Jul 17, 2005 9:44 pm, edited 1 time in total.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Sun Jul 17, 2005 7:40 am

Your code goes into an infinite loop for the following input:

Input
1
AA

Correct Output
AA

The problem lies in the cmp function. Your code works for most cases, including repeated lowercase letters like this test case:

Input
1
aa

Output
aa

except test cases such as the first test case I posted above. Fix that bug and you should get AC.

elgeish
New poster
Posts: 3
Joined: Mon Mar 01, 2004 12:36 am

Thnx

Post by elgeish » Sun Jul 17, 2005 9:44 pm

Thnx a lot, chunyi81, i got ACC now :)

roni
New poster
Posts: 11
Joined: Tue Aug 09, 2005 11:57 am
Location: SUST, BANGLADESH
Contact:

What's difference between 195 & 10098

Post by roni » Fri Sep 09, 2005 5:46 am

my 10098 is acc. but get WA. Can anyone tell me their difference.
Any IO is usefull.
roni(SUST)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Fri Sep 09, 2005 9:36 am

As I remember - it differs in output. And treating case of letters.

Best regards
DM

PS> Compare output and input definition sections in both problem.
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

roni
New poster
Posts: 11
Joined: Tue Aug 09, 2005 11:57 am
Location: SUST, BANGLADESH
Contact:

got the casesencibility of 195

Post by roni » Sat Sep 10, 2005 12:29 am

i am very surprised how the case is treated in this problem(195). i got ur reply and taked to NAZMUL about it. Then i got ACC. So, thanks for help and reply DM.
------------------roni
roni(SUST)

User avatar
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Post by Ming Han » Sat Oct 22, 2005 11:40 am

I finally realise why I (and other ppl too) keep getting OLE...
input of aaaaaaaaaa
gives output of aaaaaaaaaa only.
Arg...
:: HanWorks ::

afzal_du
New poster
Posts: 4
Joined: Mon Oct 10, 2005 7:14 pm
Location: Bangladesh
Contact:

195 OLE -- CAN ANYONE GIVE ME SOME CRITICAL INPUT??

Post by afzal_du » Fri Jan 06, 2006 5:40 pm

I've tried many ways but still getting OLE. I've read previous posts but still could not find any cases where my code failed to produce the right output. Can anyone help me finding this?
Here is my code

Code: Select all

//acm195 Anagram
Removed After Acc.. 
Last edited by afzal_du on Sun Jan 08, 2006 7:17 pm, edited 1 time in total.

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Re: 195 OLE -- CAN ANYONE GIVE ME SOME CRITICAL INPUT??

Post by tan_Yui » Sun Jan 08, 2006 9:28 am

Your code seems good, but it's too small length to store the input string.
You will get 'Accepted' after changing the array size. :)
For example,

Code: Select all

1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
when this input was coming, your code will handle illegal processes.

With my test, I think the size 100(or 99?) is enough for this problem.

Best regards.

afzal_du
New poster
Posts: 4
Joined: Mon Oct 10, 2005 7:14 pm
Location: Bangladesh
Contact:

Post by afzal_du » Sun Jan 08, 2006 7:15 pm

Thanks I've got acc now!
I thought that an array overflow will give a runtime error -- why ole??

User avatar
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

195

Post by Roby » Thu Mar 23, 2006 8:18 am

Can someone give me hints or show where's my mistake from my code below:

Code: Select all

CUT AFTER AC
It did output correctly but why I got Runtime Error. Someone please help me...
Last edited by Roby on Tue Mar 28, 2006 2:31 am, edited 1 time in total.

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Post by serur » Sat Mar 25, 2006 12:04 am

It seems to me you may mislay the possibility of input string being even longer than 100 characters, or if I am mistaken myself?
Anyway, I got this one accepted a week ago and I used malloc- i..e. without any assumptions about the length, simple stupid backtracking and a trick about "alphabetical order" not "ascii oredr"- all that is needed for this one 195 :)

User avatar
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Post by Roby » Sun Mar 26, 2006 6:53 pm

OK, I've changed my code but it gave me OLE. Here's my code:

Code: Select all

CUT AFTER AC
Does the comparer function do the correct things? I need hints here. Thanx in advance.
Last edited by Roby on Tue Mar 28, 2006 2:31 am, edited 1 time in total.

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Post by serur » Sun Mar 26, 2006 8:42 pm

I don't feel quite sure about that, but I remember hearing somewhere that that what you have done int your grouping funcction(namely, returned char *r- address of a temporary variable) is not good...
though it may be not the case here, since OLE is caused by infinite loop...
Hope this will be of some help.
Your comparison function seems to be right, though I had troubles with compiling your code on my machine, only why don't you use islower() isupper( ) builtin functions of <ctype.h>? and 32='a'-'A' I guess...

User avatar
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Post by Roby » Tue Mar 28, 2006 2:29 am

Thanx for the help, finally I got AC :) I've just known that the islower/isupper is support in OJ.

Post Reply

Return to “Volume 1 (100-199)”