Question
1. Swap Write a function to swap two integers, and answer the following questions (you can have them answered in your comments, or in your
1. Swap
Write a function to swap two integers, and answer the following questions (you can have them answered in your comments, or in your report preferably):
Whats the return type of your swap function? Why?
Whats the type of the arguments of your swap function? Why?
Whats the meaning of * in your argument list?
For each line in your swap function code block:
i.If there is a operator involved, explain what the right value and what the left variable are.
ii.If there is involved, explain what it is for. (If appears twice in a line, you need to have explanations for both)
How do you call the swap function (i.e. What do you pass as arguments for the function call)? Why?
Write a function to swap two integer pointers, and answer the same questions in a).
2. Stats
Write a function to return the pointer of the min of an integer array. Call it in your main function and then change the value of the min element into -999. Answer the following questions (you can have them answered in your comments, or in your report preferably):
Whats the return type of your min function? Why?
What are the arguments of your min function? Why do you need them?
For each line (except the for loop line) in your min function code block:
i.If there is a operator involved, explain what the right value and what the left variable are.
ii.If there is involved, explain what it is for.
How do you use the result of your min function to change the min element into -999?
Write a function to return the 3 pointers of the mean, min and max respectively of an integer array somehow. Call it in your main function and then swap the min pointer and the max pointer (not the value they point to). Answer the following questions:
Whats the return type of your function? Why?
What are the arguments of your function? Why do you need them?
Whats the meaning of * in your argument list?
For each line (except the for loop line) in your function code block:
i.If there is a operator involved, explain what the right value and what the left variable are.
ii.If there is involved, explain what it is for.
How do you call the function (i.e. What do you pass as arguments for the function call)? Why?
After you swap the min pointer and the max pointer, do you see any change in the original integer array? Why?
3. Yang Huis Triangle Again
Change the solution to Yang Huis Triangle (which can be found on Blackboard) to make each tri[i] have exactly elements.
Change your a) to make tri have exactly elements.
4. Plants VS Zombies
Plants VS Zombies is a popular game in School of Engineering and Applied Shits (SEAS). However, Vincent is not very good at this game, so he wants you to write a program to help him.
We take a simplified version of this game. There are N rows in your backyard, and N zombies walking through your yard trying to eat your brain (one zombie at each row exactly). The only way to defend the zombies is to plant peashooter on the other side of the yard. However, you need T seconds to plant one peashooter. Once the peashooter is planted, it will begin to shoot at the zombies at its row. The zombies have different speed Vi and defense Di, which means that, the zombie in the i-th row will need Vi seconds to walk through the yard, and will be killed after Di seconds of shooting. Please note that you can plant only one peashooter at each row.
Unfortunately, in some cases where the zombies are too fast and/or too strong and/or your planting is too slow, you cannot kill all the zombies in time, so the zombies will eat your brain.
Input
There are several test cases in the input. The first line of each test case contains two integers N (1 <= N <= 100) and T, indicating the number of rows and the time for planting one peashooter. Then N lines follow, each of which contains two integers Vi and Di.
Output
Output one line for each test case. If you can kill all the zombies, output N numbers separated by a space, which is, a permutation of 1, 2, , N, indicating the order of your planting. If you cannot defend your yard, output The zombies will eat your brain! in one line.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started