Page 2 of 2
Re: 282 Rename
Posted: Tue Aug 05, 2014 12:14 am
by brianfry713
Your input is not valid:
Each command appears on one line in the form: rename wildfrom wildto
Instead of
It should be:
Your input should also have "end" at the end of it.
For input:
Code: Select all
aFileb.c
aFile.b
c.axb
c.ab
ab.c
ab
end
rename a*b b*a
end
baFile.c
bFilea.a
b.xa
b.a
a.c
a
ca
end
rename *a b*c
end
AC output:
Code: Select all
rename a*b b*a
mv aFile.b bFile.a
mv ab ba
rename *a b*c
mv bFilea.a bbFilea.c
mv b.xa bb.xc
mv b.a bb.c
mv a bc
mv ca bcc
Re: 282 Rename
Posted: Wed Aug 06, 2014 2:48 am
by lighted
Thanks, i was posting that input in a hurry so i made mistakes above.

Re: 282 Rename
Posted: Thu Aug 07, 2014 11:38 pm
by lighted
Got accepted!
little joey wrote:Well, the problem statement states that both operands contain exactly one wildcard character but nothing is further said about it. This implies that all four forms (*, x*, *y and x*y) are possible in any combination. It is further explicitly stated (in the note) that we are not emulating the behaviour of MS-DOS, but letting the wildcard character match any number of printable characters (with the 14 character filename restriction). Constructions like "rename a*b b*a" and "rename * x*y" are perfectly legal according to the text.
So, no Dominik, I don't think these cases are tricky or incorrect.
Happy hunting!
-little joey
PS. It would be cruel to require knowledge of MS-DOS to solve a programming problem, especially because there are thirty-something versions and sub-versions of the thing, all with their own bugs/features. It is my strong conviction that people tend to live longer and happier without any knowledge of MS-DOS. I, alas, know too much about it...
Problem description wasn't clear for me. This problem looked hard until i got output above.
rename wildfrom wildto
from and to will both contain one wild-card character, `*'
I think possibilities of
wildfrom and
wildto should be explained a little more in problem description.
Re: 282 - Rename
Posted: Tue Dec 20, 2016 9:34 am
by RandyWaterhouse
I'm doing this problem in Python3 and get WA despite getting all test cases right which are posted in this forum and on udebug (and the ones I created myself). I think my test cases cover every possible combination, even things like "rename * *" and such. Not sure what else to check??
Also, we should assume a limit of 14 characters for filenames. Does that mean we ignore longer files? Or truncate them? For input? For output?
The AC solution in udebug handles longer filesnames????
Any help appreciated!
Re: 282 - Rename
Posted: Mon Mar 13, 2017 3:22 pm
by lighted
Yes, you should assume a limit of 14 characters for filenames. It means that there won't be longer filenames. Therefore no need to truncate them. Limit of 14 characters is for input. My accepted solution treats filenames with maximal length of 14 characters. So judge's input is valid. By the way judge's input contains at most 10001 filenames at each dataset.
To get help you could describe your algorithm. I use following algorithm:
1. Find position of * and divide wildfrom (oldname) into two parts - before * and after *. Filename = A*B, where A is first part and B is second. Some of this parts can be empty.
2. Divide wildto into two parts - before * and after *. Filename = C*D, where C is first part and D is second. Some of this parts can be empty.
3. For each FILENAME in the list we check two things. If A is prefix of FILENAME and B is postfix of FILENAME. I.e. check if FILENAME = AmiddleB, where middle is middle part of FILENAME.
4. if checking is OK, replace A by C and replace B by D. I.e. answer is CmiddleD
Hope it helps.