Вы находитесь на странице: 1из 21

Find Path

Problem Description
Sam is a tourist, One day he plans to go one country where there are N cities and each pair of city is connected to each other by a bidirectional road. Sam want to visit each city exactly once and he wants to start in one city and end in another city after traveling exactly N-1 roads. You have given a String[] path. If the j-th column of the i-th row of paths is '1', he must travel the road that connects city i and city j.

Suppose there are three cities(A,B,C), and Sam want to travel path between city A to city C. So there are 6 possible paths P(3,2)=6. For this example String[]path is {"001","000","100"} But only 4 paths allowed for Sam that are (B->A->C),(A->C->B),(B->C->A),(C->A->B) and paths( A->B->C) and (C->B->A) are not allowed because path A->C or C->A is not covered. So you have to find the possible paths where String[] path is given..

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files . 3. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

2.

4.

Write your solution in .c file

Step 1:
In your Solution File:

1.

Add Function int countPaths(char** paths)

Step 2: 1.
Pass the following parameter to the function countPaths() path is a character pointer represents the path in a matrix format as mentioned in the problem description.

Step 3:
Write the appropriate code as mentioned in the problem description by following the below given Constraints.

1. 2.
3. 4. 5.

The input should be the character array for the method, which basically shows an nxn matrix for the desired garph (The connected Cities) This matrix shows which path Sam have to travel. You need to figure out the number of possible paths which covers the path that Sam have to travel. Your method should return the number of possible paths. If the char** paths is null then your method should return -1.

The prototype of the function is:


int countPaths(char** paths) Function will take a character pointer which is the representaion of the paths and return the feasible number of paths.

Constraint:

If the given path is null then return -1 ..

Example 1
Input: {"001","000","100"} Output: 4

Example 2
Input: {"000","100","000"} Output: 0 Explanation:There is no path which is satisfying the above condition.

For C solutions
Header File : FindPaths.h File Name : FindPaths.c Function Name : int countPaths(char** paths);

For C++ solutions


Header File Class Name Function Name FileName : : : : FindPaths.h FindPaths int paths); countPaths(char**

FindPaths.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Line Intersection
Problem Description
Suppose you have N number of points in 2D Identify the straight lines with the given set of You have to find the possible intersection from identified set of The intersecting lines must not share any common If intersection is possible then return true otherwise Points are always Integer Example: Suppose the given points[][]={{1,0},{0,1},{1,1},{2,4}},then possible line segments will be: plane. points. lines. points. false. type.

There

are

no

any

intersection

in

the

given

2D

points,So

output

will

be

false.

If the given points[][]={{1,0},{0,1},{1,1},{2,4},{0,0}},then these points will be intersect each other at any points,So the output will be true

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory.

2.
3.

Download the Support files by clicking the Get Support Files. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

4.

Write your solution in .c file

Step 1:
In your Add a function bool intersections(int points[][]). Solution File:

Step 2:
Pass the following parameter to the function intersections().

int

points[][] :points is a two dimension integer array.

Step 3:
Write the appropriate code to find the subset whose sum is zero based on below given Constraints. 1. 2. 3. In this problem you have to find the intersection of lines formed by the given points is possible or not. All the points are in 2D plane. End point of two intersecting lines should not be common. public boolean intersections(int points[][]) will return true when lines will intersect and false when lines doesn't intersect. int points[][] is Integer two dimensional array of points in the 2D plane If the given points in 2D array is null then return false. If intersection is possible then return true otherwise false

4. 5.
6. 7.

The prototype of the function is:


public bool intersections(int points[][]) The function will take a two dimension integer array, which represents the set of points and returns the corresponding boolean value as per the problem statement.

Constraint:

If the given points in 2Darray is null then return false .

Example 1
Input: points[][]: {{1,0},{0,1},{1,1},{2,4},{0,0}} Output: true

Explanation:When we will draw the lines according to given points then they will intersect each other.

Example 2
Input: points[][]: {{1,0},{0,1},{1,1},{2,4}} Output: false

For C solutions
Header File : LineIntersection.h File Name : LineIntersection.c Function Name : bool intersections(int points[][]);

For C++ solutions


Header File Class Name Function Name FileName : : : : LineIntersection.h LineIntersection bool intersections(int points[] []); LineIntersection.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Context Free Grammar


A context-free grammar (CFG) is a set of recursive rewriting rules (or productions) used to generate patterns of strings. A CFG consists of the following components:

a set of terminal symbols, which are the characters of the alphabet that appear in the strings generated by the grammar. a set of non-terminal symbols, which are placeholders for patterns of terminal symbols that can be generated by the non-terminal symbols.

a set of productions, which are rules for replacing (or rewriting) non-terminal symbols (on the left side of the production) in a string with other non-terminal or terminal symbols (on the right side of the production). a seed, which is a special non-terminal symbol that appears in the initial string generated by the grammar.

To generate a string of terminal symbols from a CFG, we:

Begin with a string consisting of the start symbol; Apply one of the productions with the start symbol on the left hand side, replacing the start symbol with the right hand side of the production; Repeat the process of selecting non-terminal symbols in the string, and replacing them with the right hand side of some corresponding production, until all non-terminals have been replaced by terminal symbols.

For A B D D

example, = = bB | = =

this b |

specification: BD Bb dD d

with A as the seed represents the set of words that have one or more b's followed by one or more d's (bd, bbd, bddd, bbbddd, etc.). Above production grammar contains string bbd. So your task is to find out the given string can be formed by given grammar or not. If that string can formed by the given grammar then return true otherwise false.

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files . 3. You will find the problem directories containing: problem.h file problem.c file in your work directory.

2.

4.

Write your solution in .c file

Step 1:
In your Solution File:

Add method int checkString(char** production, char seed, char* str)

Step 2:
Pass the following parameter to the method checkString()

1. 2.

production is a character pointer array represents the available productions for the CFG as mentioned in the problem description. seed is a character,which is a special non-terminal symbol that appears in the initial string generated by the grammar.

3.

str is a String which can be created by the given productions.

Step 3:
Write the appropriate code as mentioned in the problem description by following the below given Constraints. 4. The first input should be the String Array which specify the production to the given grammer in the format given below: {"S=aSa" , "S = bSb" , "S=aa" , "S =bb"} 5. 6. 7. 8. 9. The second input is the seed character,which is a special non-terminal symbol that appears in the initial string generated by the grammar. The third input is the string itself, which you have to determine whether it is generated by the above given production You need to figure out whether the string (the third input) can be generated by the given production (the first input) by using the seed (second input) as a initial non-terminal symbol. Your method should return true if it can be generated else return false If the given production string is null then return false.

The prototype of the function is:


int Where checkString(char** production seed str is the string . production, is is char the seed, char* str) string array. the character.

Constraint:

If the given production string is null then return false.

Example 1
Input: Production String: {"S=aSa" , "S = bSb" , "S=aa" , "S =bb"} seed character: S Desired string: "abaaba" Output: true Explanation:The string "abaaba" can S=aSa---->S=a(bSb)a------->S=ab(aa)ba---------->S=abaaba formed by using production

Example 2
Input: Production String: {"A = BD", "B = bB | b | Bb", "D = dD", "D = d"} seed character: A Desired string: "bbb" Output: false

For C++ solutions


Header File Class Name Function Name FileName : : : : ContextFreeGrammar.h ContextFreeGrammar int checkString(char** production, char seed, char* str); ContextFreeGrammar.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Convex Hull
Problem Description
Computer graphics deals with representation of graphical constructs into mathematical models. A point is represented by its coordinates (x, y). One of very popular algorithm is called "convex hull" where you are given a set of points in a plane. You have to find a smaller set of points such that all the other points are inside this smaller set of points. See below image for a convex hull idea by imagining an elastic band which engulfs the set of points.

You can use any algorithm of your choice to solve the convex hull problem, though we will suggest an algorithm which uses divide and conquer technique. A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. In divide and conquer algorithm for convex hull problem, 1. 2. 3. Divide the points into two equal sized sets L and R such that all points of L are to the left of the most leftmost points in R. Recursively find the convex hull of L (left hull) and R (right hull). Merge the left hull and the right hull to get the final hull. (Hint: merging may have to do with looking for the topmost points and the bottom most points in each hull).

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

2.
3.

4.

Write your solution in .c file

Step 1:
In your Solution Add a function struct convexhull* getConvex(int points[][2], int noofcoord). File:

Step 2:
Pass the following parameter to the function getConvex().

int int

points[][2] :points represents coordinates of the points in the set. noofcoord: noofcoord represents number of coordinates of the points.

Step 3:
Write the appropriate code for the given problem on below given Constraints. 1. 2. 3. 4. Here you have to write a code for a very popular algorithm is called "convex hull" where you are given a set of points in a plane. You have to find a smaller set of points such that all the other points are inside this smaller set of points. You can use any algorithm of your choice to solve the convex hull problem. We will suggest an algorithm which uses divide and conquer technique. In divide and conquer algorithm for convex hull problem, Divide the points into two equal sized sets L and R such that all points of L are to the left of the most leftmost points in R. Recursively find the convex hull of L (left hull) and R (right hull). Merge the left hull and the right hull to get the final hull. (Hint: merging may have to do with looking for the topmost points and the bottom most points in each hull) In easy words you have to find the smallest bourdary around all the points.(where points should lie on the boundary or inside the boundary ) The Number of Coordinates should be greater than 3 else return NULL. Please read the exapmle carefully.

5. 6. 7.

The Prototype of the Function is :


struct convexhull* getConvex(int points[][2], int noofcoord); Where points represents coordinates of the points in the set, noofcoord represents number of coordinates of the points and the function returns the set of the points that makes the convex hull.

Constraint

The Number of Coordinates should be greater than 3 else return NULL.

Example 1
Input double points[][2] = {{3,1},{2,3},{1,2},{3,2},{2,4},{4,3},{4,4},{5,2}}; int noofcoord = 8; Output The function getConvex returns {{3,1},{1,2},{2,4},{4,4},{5,2}}. Explanation: The points {{3,1},{1,2},{2,4},{4,4},{5,2}} which forms the convex hull of the outer most points in which all other points present inside. Hence the function returns the position of these points.

Example 2
Input double points[][2] int noofcoord = 4; Output The function getConvex returns {{2,1},{1,3},{3,3}}. = {{2,1},{2,2},{1,3},{3,3}};

Example 3
Input double int noofcoord = 2; Output points[][2] = {{2,1},{2,2}};

The function getConvex returns NULL.

For C solutions
Header File : convexhull.h struct convexhull* getConvex(int points[][2], int noofcoord)

Function Name :

Directory Name : convexhull File Name : convexhull.c

For C++ solutions


Header File Class Name : convexhull.h : ConvexHull struct convexhull* getConvex(int points[][2], int noofcoord)

Function Name :

Directory Name : convexhull File Name : convexhull.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Queens and Knights


You are given a 8x8 chess board with out any pieces other than equal number of queens and knights. You have to place an equal number of knights and queens on the chessboard such that NO piece attacks any other piece. Each position in the board uses following to represent the status: 0 - no pieces, 1 - queens, 2 knights. Given a board with or without any pairs of queen and knight, you have to write a function addMaxPieces which adds as many pairs of queens and knights as possible and returns the updated board in the same format. You can use the fact that in the best configuration, a maximum of 5 queens and 5 knights can be placed on 8 x 8 board such that NO piece attacks any other piece. An example of such a configuration is given below

. Note that you will get 50% credit, if you add even one extra pair of queen and knight on the board correctly.

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files . 3. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

2.

4.

Write your solution in .c file

Step 1:
In your Solution File:

1.

Add method public static int[][] addMaxPieces(int[][] board)

Step 2: 1.
Pass the following parameter to the method addMaxPieces() board is a two dimension integer array, represents the chess board as mentioned in the problem description.

Step 3:
Write the appropriate code as mentioned in the problem description by following the below given Constraints. 1. 2. The input should be the two dimension integer array provided to the method with some entries in the matrix. The entries specify the position of the Queens and Knights in the chess board (matrix). 1 for Queen and 2 for Knight

3. 4. 5.

6.

You need to figure out the position of the Queens and Knights in the chess board, which can be additionally added to the board so thus no peices will attack anyone Your method should return the chess board that is the two dimension array with some additional entries. If your method will able to add atleast one pair of Queens and Knights, you will get the 50% credit. Read Constraints carefully.

The Prototype of the Function is :

int** addMaxPieces(int** board) takes a chess board as input and tries to add as many knight and queen pairs as possible and return the board in same format.

Constraints

The positions on the board can have only 0,1,2 values, else return the board as it is. Input board should have equal number of queens and knights (if any), else return the board as it is. In Input Board, no piece can attack any other piece, else return the board as it is. Input board should be of size 8 x 8, else return the board as it is.

Example 1
Input board[0][2] = board[1][5] board[6][4] = board[6][7] = board[7][3] = 2; Output The X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = 7,4 Piece = K The picture for this example 0,2 1,5 2,1 3,6 5,0 7,7 6,4 6,7 7,3 Piece Piece Piece = board[2][1] = 1;

function Piece Piece Piece Piece Piece Piece = = = K K K = = = Q Q Q = = =

returns input input input Q Q K input input input

Example 2

Input board[0][2] board[6][4] = board[6][7] = 2; Output The X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = X,Y = 7,4 Piece = K

board[1][5]

1;

function 0,2 1,5 2,1 3,6 5,0 7,7 6,4 6,7 7,3 Piece Piece Piece Piece Piece Piece Piece Piece Piece = = K K = = = Q Q = = = =

returns input input Q Q Q K input input K

Example 3
Input board[0][2] board[6][4] = 2; Output The X,Y = /> X,Y X,Y X,Y X,Y X,Y X,Y = X,Y X,Y X,Y = 7,4 Piece = K 0,2 = = = = = 6,4 = = 6,7 7,3 2,1 3,6 5,0 7,7 Piece Piece Piece = 1;

function Piece 1,5 Piece Piece Piece Piece = K = = = Piece Q = = = = =

returns input Q Q Q Q K input K K

For C solutions
Header File Function Name Directory Name File Name : : : : queenknights.h int** board) addMaxPieces(int**

queenknights queenknights.c

For C++ solutions


Header File Class Name Function Name : : : queenknights.h QueenKnights int** board) addMaxPieces(int**

Directory Name FileName

: :

queenknights queenknights.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Match the group


In Computer Science branch of ABC College of Engineering, there are n students; numbered 0 through n1(where n is an odd number). As usual, each of the student has some friends within the same branch, and each of them knows how many friends each of the other student has. Friendship is symmetric, so if a student 0 is a friend of student 1, then student 1 is also a friend of student 0. An assignment is given to the students by Prof. XYZ, for which groups of 2 are to be formed within the classroom, for which each student has been asked to submit the name of the student with whom they want to form their assignment group. Each student i has got the freedom to choose exactly 1 other student (i+k) %n as his/her partner for the assignment, not necessarily a friend; and each student is free to select anyone. For example, if a student 0 selects student 1 then too student 1 can select any student other than 0 as his group-mate. You being the Prof. XYZ ask each student to submit the "sum of the number of friends each of the student in class have, other than the student himself and the one he chose for the assignment group. For example, if student 0 selects student 1 for his group, he should submit (the number of friends kid 2 has) + (the number of friends kid 3 has) + ... + (the number of friends kid n-1 has). You are given a vector sumFriends, where the i-th element (0-indexed) is the answer given to you by student i. To make the things complicated for you, some of the students might not be telling the truth. Return "IMPOSSIBLE" if it is impossible for all the given answers to be accurate. Otherwise, return "POSSIBLE". Note: all quotes for clarity

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files . 3. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

2.

4.

Write your solution in .c file

Step 1:
In your Solution File:

1. 2.

For C++ : string findFriends(vector<int> sumFriends, int k) For C : char* findFriends(int sumFriends[],int N, int k)

Step 2:
1. Pass the following parameter to the method findFriends()

sumFriends is an integer array, represents the answer given by each students as mentioned in the problem description. k is the minimum number of friend a student had.

Step 3:
Write the appropriate code as mentioned in the problem description by following the below given Constraints.

Your method will take sumFriends as an integer array, which are the replies given by the students and k as an int which is the minimum number of friends a student had. Your method should analyze the input and tell whether the combination is possible or not as mentioned in the problem description. Read the Constraints carefully

The Prototype of the function is defined below as per the language:


For For C C++ : string findFriends(vector<int> : char* findFriends(int sumFriends[],int N, int k) sumFriends, int k)

Where the function takes sumFriends and k as the input and returns a string ("IMPOSSIBLE" or "POSSIBLE") that is case sensitive

Constraints

sumFriends will contain odd number of elements. sumFriends will contain between 3 and 49 elements, inclusive. Each element of sumFriends will be between 0 and 9999, inclusive. k will be between 1 and (number of elements in sumFriends)-1, inclusive.

Example 1
Input {8, 2 Output Function Explanation: 9, 8, 8, 9}

returns

"POSSIBLE"

We can get such sums only if student 1 has 2 friends and all other students have 3 friends. Such a situation is possible. For example:

Student 0 1 2 3 4

His/her friends 1, 3, 4 0, 2 1, 3, 4 0, 2, 4 0, 2, 3

Example 2
Input {7, 6, 2 Output Function Returns "IMPOSSIBLE" 5, 4, 4}

Example 3
Input {5, 6, 1 Output Function Returns "POSSIBLE" 5, 4, 4}

Example 4
Input {1, 1 Output Function Explanation: Here student 2 selects student 0, so he tells us the number of friends of student 1. But it's obviously impossible for student 1 to have 3 friends. 2, 3}

Returns

"IMPOSSIBLE"

For C solutions
Header File : friend.h Function Name : char* findFriends(int sumFriends[],int N, int k) File Name : friend.c

For C++ solutions


Header File Class Name Function Name FileName : : : : friend.h Friend string findFriends(vector<int> sumFriends, int k) friend.cpp

General Instructions

The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Data Storage
In this problem, you are given a network. Network is built upon n servers connected by bidirectional wires. Two servers can be directly connected by at most one wire. Every two servers are connected with some path in the network. Each wire has a fixed positive cost associated with the transmission. The distance D(V, W) between two servers V and W is defined as the smallest cost of any path connecting V and W in the network. The cost of transmission to the same server is 0 i.e. D(V, V) = 0 for all V. The cost is same on both sides of the transmission. Some servers offer more services than others. Therefore each server V is marked with a number r(V), called a rank. At each server, data about nearby servers needs to be stored. However, for a given server, not all servers are interesting to store data about. The data about distant servers with low ranks need not to be stored. More specifically, a server W is interesting for a server V, if for every server U such that D(V, U) = D(V, W), the following condition is satisfied: r(U) = r(W). Let B(V) denote the set of servers which are interesting for a server V. In this problem, you need to compute the total sum of sizes of all sets B(V), which represents the total data need to be stored in the network.

Instructions to use Open PBT Client:


1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory. Download the Support files by clicking the Get Support Files. You will find the problem directories containing: o problem.h file o problem.c file in your work directory.

2.
3.

4.

Write your solution in .c file

Step 1:
In your Solution Add a method int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires). File:

Step 2:
Pass the following parameter to the method calulateDataSize().

int rank[] : represents the ranks of the severs as mentioned in the problem description. int wires[][3]: contains wire information (source server, destination server and transmission cost). int totalRank: represents number of ranks. int totalWires: represents total number of wires.

Step 3:
Write the appropriate code as mentioned in the problem description by following the below given Constraints. 1. 2. 3. Your method will take rank as an integer array, wires as a two dimension integer array which contains the information about the wires i.e;(source server, destination server and transmission cost) and the respective number of ranks and wires. The method will calculate the total number of elements in each and every set ( B(V) ). In turn the sets can be calculated by the way given in the problem statement. Read the Constraints carefully.

4.

The prototype of the function is


int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires)

Where rank[i-1] is rank of ith server (1,2,...N), wires contains wire information (source server, destination server and transmission cost), totalRank will gives you the number of ranks and totalWires will gives you the total number of wires. This function returns the total data storage required or -1 in case of error or invalid input condition.

Constraints

Every two servers are connected with some path in the network. Otherwise return -1 for error. Maximum number of servers is 10. Otherwise return -1 for error. The rank of each server has to be in range: 1= rank = 10. Otherwise return -1 for error. Transmission cost has to be more than zero between 2 different servers (Negative costs not allowed). Otherwise return -1 for error.

Example 1
Input rank = wires[0] = {1, 4, 30} respectively wires[1] = wires[2] {2, 3, 1, 1} and represents ( source server, destination server and transmission cost ) and {2 ,3, 20} and = {3 ,4, 20} totalRank = 4

totalWires = 3 Output Function "calulateDataSize" returns 9. Explanation because B(1) = {1, 2}, B(2) = {2}, B(3) = {2, 3}, B(4) = {1, 2, 3, 4}.

Example 2
Input rank = {2, 3, 2, 1} and wires[0] = {1, 2, 30} represents ( source server, destination server and transmission cost respectively) and wires[1] = {2, 3, 10} and wires[2] = {3, 4, 10} totalRank = 4 totalWires = 3 Output

Function "calulateDataSize" returns 8.

Example 3
Input rank = {2, 3, 2, 1} and wires[0] = {1, 2, 30} represents ( source server, destination server and transmission cost respectively) and wires[1] = {2, 3, 10} totalRank = 4 totalWires = 2 Output Function "calulateDataSize" returns -1.

For C solutions
Header File Function Name File Name : : : datastorage.h int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires) datastorage.c

For C++ solutions


Header File Class Name Function Name File Name : : : : datastorage.h DataStorage int calulateDataSize(int rank[], int wires[][3], int totalRank, int totalWires) datastorage.cpp

General Instructions
The file / class names, functions, method signatures, header files to be used are mentioned in
* the problem statement. Do not use your own names or change the method signatures and

fields. You can add any number of additional methods.


* Do not forget to mention the file extension, either .c or .cpp as the case maybe.

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2. * Incase of iostream.h specify as iostream only.
*

Вам также может понравиться