Sei sulla pagina 1di 10

 Question 1: Write a program that simulates a gambling game. Each turn you choose among nine possible guesses.

As many as five guesses may be made in a turn for each turn. For each turn, the program will generate a random number between 1 to 36. Each correct guess will be rewarded with the points based on how many of your current points you have risked. LOW 1 2 3 4 5 6 7 8 9 10 11 12 MEDIUM 13 14 15 16 17 18 19 20 21 22 23 24 HIGH 25 26 27 28 29 30 31 32 33 34 35 36 LEFT CENTER RIGHT A game board divides the number the number into rows and cols, as shown in the figure. This board provides the basis for your guesses. You can guess whether the random number is even or odd. In this case, you get 1 point for each point risked when you guess right you can guess whether the number is low (1-12), medium (13-24) or high (25-36). In this case, you will get 2 points for each point

risked. You can also guess left, right or center as shown in the figure. In this case, you get 2 points for each point risked when your guess is correct. Finally, you can guess specific number between 0 and 36. In this case you get 36 points for each point risked when your guess is correct. To make this round more interesting, each round allows up to five guesses none of the five may be correct or any number up to all five may be correct. The program stops when player quits or when the player is out of points. The program 1st asks then number of points the user wants to start with as shown below. How many points would you like ? 5000 The program then prints the guess menu and allow up to five guesses, as shown below.

Guesses O E L M H F C

choices Odd Even Low medium High Left Center

R N

Right Number

How many guesses would you like? 5 Guess 1: Enter your choice? L Points at risked? 20

Guess 2: Enter your choice? H Points at risked? 15

Guess 3: Enter your choice? N Enter your number: 18 Points at risked? 20

Guess 4: Enter your choice? O Points at risked? 120

Guess 5:

Enter your choice? L Points at risked? 0

After all guesses have been made, the program generates the random number and displays the following message: My number is: 31 The program the prints the situation of the player: Previous points: 200

Guess 1 2 3 4 5

Type L H N O N

Number

18 20

Amount 20 15 20 120 10

Won/lost -20 +30 -20 +120 -10

You won 100 points in this turn. Your new balance is: 2100 points. Do you want to play again (Y or N)? Y

Some special rule: the minimum amount risked on a guess is 0. The maximum is the player s current balance. You need to verify that at no time are the point risked more than the player s current balance. Any

combination of guesses is allowed on a round as long as the total does not exceed the players balance. Some hints: You must use at least four arrays, each of five elements. The array hold the guess information for the kind of guess, chosen number (in case the player chooses a number), amount of the guess and points won/lost.

 Question 2.

In a field trees are planted row-wise, each tree being of different height. A monkey, wandering somewhere in the field is searching for a fruit. Two trees will have fruit on it. Monkey has the idea on which tree the fruit is. So it wants to fetch the nearest fruit. But in order to get to that fruit he has to climb each tree that comes in his way. Monkey climbs 3 meters in one jump and slips down by 1 meter. And monkey can only go straight i.e. forward, backward, right or left. It cannot climb a tree that is diagonal to the tree on which it stands. The nearer tree is the fruit bearing tree for which the monkey makes minimum hops and climbs less number of trees.

Input: y Ask user to input size of the field, store it in n x m array. y Take the height of each tree as input (each cell will represent the height of the corresponding tree). y Ask the user on which tree the fruit is located. y Ask from user where is the monkey currently standing. Output: y Print the nearer fruit tree position.

 Question 3 Move from ring to adjacent ring, starting from the bottom left corner and finishing in the top right corner. Moving towards the top right corner collect all the numbers on your way and add them. When you reach the top right corner ring print the highest possible total and also the numbers. Note: Maximum number of moves to cross an N x N grid is (2N 1),

2 3 2 2 2

2 3 3 3 3

2 2 2 2 3

3 3 3 2 2

2 2 2 3 3

Input: Take size of the array from user, it has to be NXN array. (Limit N = 50) Take the input for each cell from user. (Range of Values 1 100) Output: Display the highest possible total and also the numbers which contribute to the highest total.

 Question 4: A long time ago in some country in Asia, Civil wars took place. Each of n cities wanted to seize power. That's why sometimes one city gathered an army and sent it to campaign against another city. Road making was difficult, so the country had few roads, exactly n - 1. Also you could reach any city from any other city going on those roads. Even during the war, the Oriental people remained spiritually rich and appreciated the beauty of nature. And to keep the memory of this great crusade for the centuries to come, they planted one beautiful tree by the road on which the army spent most time. The Oriental people loved nature, that's why if there were several such roads, then one tree was planted by each of them. Recently, when the records of the war were found, it became clear that each city attacked each other one exactly once. There were exactly n(n - 1) attacks in total. Everyone has been wondering what road after those wars became the most beautiful, that is, by which road they planted the largest number of beautiful trees. Input: The first line contains an integer n (2 n 105), which represents the number of cities. Next n - 1 lines contain three integers each: the numbers of cities ai, bi (1 ai, bi n), connected by the i-th road and the number of days di the army spends to go on it (1 di 109). The lengths of several roads may coincide. Output:

Print on the first line two integers the number of beautiful trees on the most beautiful road and the number of the most beautiful roads. Print on the second line the list of the most beautiful roads in the sorted order by the numbers' increasing. The roads are numbered from 1 to n - 1 in the order in which they are given in the input data. Please, do not use %lld specifier to write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specifier). Sample test(s) Input: 2 215 Output 21 1 Input 6 121 135 342 353 364 Output 16 1 2

Potrebbero piacerti anche