辅导案例-COSC 326 2020
COSC 326 2020 Summer School Étude 8 Arithmetic A common sort of puzzle or problem one sees in newspapers, particularly at the be- ginning of each year goes along the lines of “make up a formula whose value is 2018, using the numbers 1 through 10 in that order”. Of course the rules of the game are never entirely clear - in particular whether brackets are allowed, and what operations are permissible. In this étude we’ll look at a simplified model. The only operations allowed are + and × and brackets are not permitted. However, we’ll consider both ‘proper’ order of op- erations where 1 + 2× 3 = 7 and ‘left to right’ where 1 + 2× 3 =LR 9. Task Input from stdin will be a sequence of scenarios. Each scenario is exactly two lines. The first line is the numbers to use, and the second line consists of a target value, fol- lowed by a space, followed by the character N or the character L indicating whether normal order of operations, or left to right order is to be assumed. The output for a scenario should be a character representing the order used, then the target value, and finally an expression of the required value (using the character * for multiplication, and with spaces before and after each operation), or the word impossible. Example Input: 1 2 3 7 N 1 2 3 9 L 1 2 3 100 N Output: N 7 1 + 2 * 3 L 9 1 + 2 * 3 N 100 impossible COSC 326 2020 Summer School Étude 8 Relates to Objectives 2.1-3 2.5 2.10 3.4 3.5 (2 points, Individual)