Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

NEXTPERM - Next permutation

Dla danego wyrazu n, wypisz kolejną permutację liter tego wyrazu.

Input

W pierwszej linii znajduje się liczbe testów t (t<101).

W każdej z t linii znajduje się liczba l (l<20), która oznacza długość wyrazu n. W kolejnej linii będzie się znajdować wyraz n.

Output

Dla każdego wyrazu n wypisz kolejną permutację liter tego wyrazu lub ERROR jeśli taka permutacja nie istnieje.

Przykład

Wejście:
2
3
acb
3
cba
Wyjście:
bac
ERROR


Added by:Piotr Kąkol
Date:2009-12-22
Time limit:4.900s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: SCM qobi
Resource:Permutation

hide comments
2013-11-03 15:18:29 Piotr KÄ…kol
Thanks for the info! I'll fix it along with LOOK_SAY.
Edit: Fixed and rejudged.

Last edit: 2013-12-07 00:20:24
2013-11-02 22:20:09 Mitch Schwartz
Test cases are weak; my submission 10406350 doesn't handle cases like cfedba properly but still passed.

Last edit: 2013-11-02 23:03:16
2012-09-01 19:12:04 Piotr KÄ…kol
@Avinash - Your answer for:
18
bdcofgpqarmhnelikj

is: bdcofgpqarmhneljki.
2012-09-01 13:11:07 AVINASH JAIN
Its giving wrong answer again and again. My program is running for the test cases given and for some random test cases. Please give some more test cases. Can n be zero(0).
2010-02-19 22:50:13 Piotr KÄ…kol
1) length < 20
2) Yes. For example succesive permutations of length 3 are:
abc
acb
bac
bca
cab
cba
Then You should print ERROR.
3) Yes, only lowercase (but ERROR is made of uppercase letters).
4) No, they can't.
5) Good luck. ;-)
2010-02-19 14:39:59 Alessandro Ferreira - UFMS
What's the limit for 'l'?
My task is to find the next permutation in lexicographic ordering ?
Does the string contain only lowercase letters? May appear repeated elements in string?

Last edit: 2010-02-19 18:33:11
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.