282 - Rename

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

Moderator: Board moderators

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

Re: 282 Rename

Post by brianfry713 »

Your input is not valid:
Each command appears on one line in the form: rename wildfrom wildto
Instead of

Code: Select all

rename
a*b b*a
It should be:

Code: Select all

rename a*b b*a
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

Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 282 Rename

Post by lighted »

Thanks, i was posting that input in a hurry so i made mistakes above. :oops:
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 282 Rename

Post 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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
RandyWaterhouse
New poster
Posts: 4
Joined: Tue Dec 13, 2016 1:41 pm

Re: 282 - Rename

Post 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!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 282 - Rename

Post 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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 2 (200-299)”