Gigel is back at it with a new challenge. He wants to create a new game for his friends to play. However, this kind of project is hard for a single person to handle, so he asks you for help on the backend for the console system. He gives you his work paper regarding the story part of this game:
Name: Console Simulator 2017
Genre: Simulator, Action, Horror
Description: You are trapped in a room, where the only working thing is a computer. As you start poking around, you find out that the console you are sitting at is controlling the whole building, and also your life. Prepare yourself for a run for your life while writing in the console.
The system that you must design has to simulate a console. It has to emulate a console similar to a UNIX one. Here is the list of commands that you have to emulate, and the details for each one:
ls
- Lists the subdirectories and the files contained by the current folder. If it has the-r
argument, it will list the subdirectories and files recursively.cd
- Changes the directory to the specified one. If the path starts with~/
, you will have an absolute path.grep
- Searches through a list and makes a result list. The search query is a regex subset. It will only use the^
,$
and.
special characters. The^
and$
are position markers, which can be put at the beginning or the end of the query. The.
character is considered a wildcard, and can be replaced by any other character. See the sample for more details.mkdir
- Creates a new directory in the current folder.touch
- Creates a new file in the current folder.pwd
- Prints the current path.exit
- Exits the console.
Input Specification
Firstly, you will receive the initial folder structure.
On the first line, you will have a number .
On the next lines, you will find the current depth and the name of the file/folder.
After this, you will find commands, and you will stop reading when you reach the exit
command.
Output Specification
The outputs from the commands are always separated by one empty line. After the last command, be sure to also have an additional blank line.
Constraints and Notes
- Each folder will have at most subdirectories and files.
- The maximum depth will be .
- In a folder there will not be two subdirectories or files with the same name.
- A file always has an extension. (ends with
.<ext>
) - The output of each command must be printed sorted lexicographical.
- Always print
\n\n
after the output of a command, even if the command does not print anything. - If you don't print
\n\n
after the output from every command that gives output, you will getWA
. - Be sure to ask in the comments if you don't find a piece of information.
Sample Input
35
0 usr
1 home
2 homespace
3 desktop
3 helper
2 derringer
3 games
4 steam
5 magico
6 map
7 part1.map
7 part2.map
6 exe
7 steam_api.dll
7 magico.exe
5 europauniversalis4
6 history
7 data.txt
6 map
7 map.dat
6 common
3 nothere
3 yarp
0 system
1 util
2 lsgrepandcd
3 nofiles
2 gcc
2 g++
1 xgraphicssystem
2 source
2 binariesbin
3 server.exe
2 gource
2 orrel
cd usr
cd home
cd derringer
ls
ls -r
ls | grep a
ls -r | grep a
cd games
ls
pwd
cd ~/
ls -r | grep \.exe$
ls -r | grep ^g...
ls -r | grep ^g..$
exit
Sample Output
games
nothere
yarp
common
data.txt
europauniversalis4
exe
games
history
magico
magico.exe
map
map
map.dat
nothere
part1.map
part2.map
steam
steam_api.dll
yarp
games
yarp
data.txt
europauniversalis4
games
magico
magico.exe
map
map
map.dat
part1.map
part2.map
steam
steam_api.dll
yarp
steam
~/usr/home/derringer/games/
magico.exe
server.exe
games
gource
g++
gcc
Comments
"If the path starts with
~/
, you will have an absolute path"In bash, doesn't
~/
go to your home folder instead of the root drive...?What's the criteria for full points? I got AC but only partial points. It doesn't seem to involve run time, memory usage, or file size.
Edit: An AC verdict can be given for incorrect output. To full solve, fix the output.
Could someone give a hint for full points on the final test case? Does it have to do with quotes in the command -
makedir "directory name with spaces"
?Edit: Never mind. Problem was related to how I stored my files and folders.
What is wrong with my code? Only the second test case fails. I believe that I have fixed most of the bugs in my code (the cd command), but still don't know why the WA is occurring, especially since the third test case passes. Edit: nvm, fixed bug
how many commands are there
how long are the file and directory names?
There is no need to worry about going over the time or memory limits.
for the second command in the sample input why would
common
be printed first and not be recursively printed derringer->games->steam->magico->map->part1.map and print part1.map first?the output is to be sorted alphabetically,
The output of each command must be printed sorted lexicographical.
Is
cd ..
used (to go to the parent directory)? Iscd
used (to go the the home directory)? Cantouch
be used to create multiple files at the same time (e.g.touch a b
creates a file calleda
and a file calledb
)?(for future reference)
I did not account for either, and passed.
Will the | operator only be used after an ls command and to a grep command?
Yes.
limit of maximum number of commands?
the 20 point version of hop skip jump is here