DMOPC '16 Contest 2 P6 - Console Simulator 2017

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.2s
Memory limit: 128M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 kind of hard for a single person to handle it, so he ask 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 . characters it's a considered a wildcard, and can be replaced by any other character, and ^ and $ are position markers, which can be put at the beginning or the end of the query. 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 N.
On the next N 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

  • 0 \le N \le 105\,000
  • Each folder will have at most 1000 subdirectories and 1000 files.
  • The maximum depth will be 100.
  • 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 commands that gives output, you will get WA.
  • 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


  • 1
    prophet  commented on April 15, 2020, 10:30 p.m. edit 2

    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.


  • 0
    GeeTransit  commented on Jan. 10, 2020, 7:18 a.m.

    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"?


  • 1
    Josh  commented on Dec. 9, 2019, 7:49 a.m. edited

    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


  • 2
    discoverMe  commented on July 3, 2019, 12:11 p.m.

    how many commands are there

    how long are the file and directory names?


    • 2
      c  commented on July 3, 2019, 1:12 p.m.

      There is no need to worry about going over the time or memory limits.


  • 2
    discoverMe  commented on July 1, 2019, 11:04 a.m. edit 2

    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?


    • 2
      Dormi  commented on July 1, 2019, 1:16 p.m.

      the output is to be sorted alphabetically, The output of each command must be printed sorted lexicographical.


  • 3
    c  commented on May 30, 2019, 8:12 p.m.

    Free 30 points!


    • 4
      Plasmatic  commented on June 26, 2019, 6:49 p.m. edited

      provided that you can have someone on hand to answer clarifications of course

      (thank you Audax!)


  • 3
    Ninjaclasher  commented on March 11, 2018, 11:34 a.m.

    Is cd .. used (to go to the parent directory)? Is cd used (to go the the home directory)? Can touch be used to create multiple files at the same time (e.g. touch a b creates a file called a and a file called b)?


    • 3
      c  commented on June 15, 2019, 12:01 p.m.

      (for future reference)

      I did not account for either, and passed.


  • 3
    nathanl3  commented on March 25, 2017, 10:12 a.m.

    Will the | operator only be used after an ls command and to a grep command?


    • 3
      WallE256  commented on March 25, 2017, 5:39 p.m.

      Yes.


  • 3
    imaxblue  commented on Nov. 8, 2016, 7:18 p.m.

    limit of maximum number of commands?


  • 13
    imaxblue  commented on Nov. 8, 2016, 6:20 p.m.

    the 20 point version of hop skip jump is here


  • 3
    d  commented on Nov. 8, 2016, 6:01 p.m.

    What is the limit on N?