Prabhanjan2

download Prabhanjan2

of 3

Transcript of Prabhanjan2

  • 7/25/2019 Prabhanjan2

    1/3

    PROBLEM 2 : FILE ORDERING

    MARKS 100

    You are developing big software that requires installation of some setup files. These

    setup files may be platform-specific or platform independent. By platform specific we

    mean that file can be installed only to that platform. Platform Independent files can be

    installed to any platform. Platform is indicated by platform string like P1 (OS = Linux,

    Processor = Intel Pentium IV).

    A file c an depend on other files. If File1 depends on File2, this means that File1 can be

    installed only when File2 is already installed.

    INPUT:

    The input begins with a line containing a number indicating number of files to be

    installed.

    Then for each file, the inputs will be

    i) The platform on which the given file will run

    ii) The file(s) on which the given file depends.

    For an example the structure of a file with the following inputs can be like:

    File 1 P1

    File2

    File3

    File4

    This means that File1 is specific for platform P1 and it depends on File2, File3 and File4and not vice versa i.e. File2, File3 and File4 should not depend on File1 and File1 can

    only run when the other three files are already installed.

    It also implies that File2, File3 and File4 can be platform independent or should run on P1

    otherwise the input given is not correc t.

    File Structures will be separated by blank space.

    OUTPUT:

    The output of the given problem should be in the form of a comma separated ordered

    list of files which are to be processed for each platform.P1::File2, File3, File4, File1

    This means for a platform P1 the files must be executed in this order.

    It is possible that there is a cycle that produces deadlock. In that case you have to print

    in this way.P1::A cycle is detected

  • 7/25/2019 Prabhanjan2

    2/3

    Cycle can be in this form:-

    File1File2File1

    This means that File1 can be installed only if File2 is already installed and File2 can be

    installed if File1 is already installed causing a deadloc k.NOTE: For particular platform, there can be more than one ordered list of files which

    are to be executed. In that case you have to print only one correc t sequence.

    Sample Input:

    10

    File1::General

    File2

    File2::General

    File3::P1File1File2

    File4

    File4::P1

    File1

    File5::P2

    File1File2File6File7

    File8

    File6::P2

    File8

    File7::P2File2

    File8::P2

    File9::P3File1

    File2File10

    File10::P3File1File2

    Output for the Sample Input:P1::File2, File1, File4, File3P2::File2, File1, File7, File8, File6, File5P3::File2, File1, File10, File9

  • 7/25/2019 Prabhanjan2

    3/3