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

alekscooper
New poster
Posts: 7
Joined: Thu May 21, 2015 9:52 pm

Re: 195 - Anagram

Post by alekscooper »

Hi everyone,

I wrote my solution in Java and here's what I did:

1) I worked with StringBuilders. I know that might be not the best option, but I'm a self-taught non-competitive guy who just learns how to code using UVa Judge.

2) The first thing I do is I sort my input string converted to StringBuilder. However, there's an implementation trick which I will talk about in 3)

3) The trick of this program is comparison, since "aaAabBbzZz" should be sorted into '"AaaaBbbZzz". To achieve that I wrote my own function to compare two chars which I call 'less' (following the name given by R. Sedgewick).

4) After that I just implemented the Narayana algorithm, which also uses my less(...) function.

My Java solution is 0.139.

If anyone needs the code, please write at akuptsov.hseATgmail.com

Sorry, I don't have a git yet, I'm a noob and perhaps I don't have super-cool code to brag about, haha )
4rchitect
New poster
Posts: 2
Joined: Fri Mar 11, 2016 1:03 am

Re: 195 - Anagram

Post by 4rchitect »

Is there a way to use std function lexicographical_compare and sort to sort the way the problem wants?
metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 195 - Anagram

Post by metaphysis »

I think the answer is negative. You should code a custom compare function as parameter for sort.
Post Reply

Return to “Volume 1 (100-199)”