Saint Louis University |
Computer Science 2100
|
Dept. of Math & Computer Science |
Topic: | Copier Reduction |
Source Code: | copier.cpp |
Live Archive Ref#: | 3393 |
Pre-lab Due: |
Thursday, 3 September 2015, 10:00am |
Submission Deadline: | Friday, 4 September 2015, 11:59pm |
Techniques: |
Loops, Conditionals, Arithmetic, and perhaps a utility function |
More Information: |
General information about labs, testing, judging utility |
The pre-lab requirement must be completed and submitted individually.
The remainder of the lab activity should be completed working in pairs. One person should submit the result, making sure that both partners' names are clearly identified in that submission.
Please make sure you adhere to the policies on academic integrity in this regard.
Read the complete problem description and then determine what the expected output should be if given the following input:
Prelab input: | Prelab output: |
225 74 3 9 34 28 6 5 27 33 6 5 0 0 0 0 |
What do you do if you need to copy a 560x400mm image onto a standard sheet of US letter-size paper (which is about 216x280mm), while keeping the image as large as possible? You can rotate the image 90 degrees (so that it is in "landscape" mode), then reduce it to 50% of its original size so that it is 200x280mm. Then it will fit on the paper without overlapping any edges. Your job is to solve this problem in general.
Input: The input consists of one or more test cases, each of which is a single line containing four positive integers A, B, C, and D, separated by a space, representing an AxBmm image and a CxDmm piece of paper. All inputs will be less than one thousand. Following the test cases is a line containing four zeros that signals the end of the input.
Output: For each test case, if the image fits on the sheet of paper without changing its size (but rotating it if necessary), then the output is 100%. If the image must be reduced in order to fit, the output is the largest integer percentage of its original size that will fit (rotating it if necessary). Output the percentage exactly as shown in the examples below. You can assume that no image will need to be reduced to less than 1% of its original size, so the answer will always be an integer percentage between 1% and 100%, inclusive.
Example input: | Example output: |
560 400 218 280 10 25 88 10 8 13 5 1 9 13 10 6 199 333 40 2 75 90 218 280 999 99 1 10 0 0 0 0 |
50% 100% 12% 66% 1% 100% 1% |
You can run the automated judge's tests on turing to test the correctness of your program (although you must still formally submit the source code via the course website). To use the judging utility, your source code must be named copier.cpp. If you are working on your own machine (or if you just want to examine the judge's inputs and expected outputs), we provide them here.
One member of the team should submit the file copier.cpp through the course submission page. Please make sure that the names of both members of the team are included in comments at the beginning of the source code.
This is a straightforward problem. You need an outer while loop because a single execution of the program must solve multiple trials (one per line). For a specific trial, solve the problem for the original orientation and for the rotated orientation and output the better of the two. You will need a conditional or two to determine the limiting dimensions.
If you want to save yourself a bit of trouble, write a utility function to compute the proper percentage for a fixed orientation. Then you can call that function twice, inverting the parameters for the rotated case.
The most common mistakes resulted from ignoring details in the problem specifications. Most importantly
Do not make any assumptions about the height being greater than or less than the width, for the paper or the picture.
Make sure to handle integer arithmetic properly. For example, if the highest possible floating-point scale factor is 70.98, the output should be 70%, because it is possible to fit the 70% image but not possible to fit the 71% image.
You are never to scale the picture to bigger than 100%.
For the record, during the actual competition, the first team in our region to complete this problem had it done 8 minutes into the day.