香港中學文憑資訊及通訊科技 模擬試卷及多項選擇題

Answer all questions. Write your answers in the DSE(D) Answer Book provided. 1. Jenny works on string pattern analysis. Consider the following algorithm for two given strings ST1 and ST2 . Line Code 1 2 3 4 5 6 7 8 t ← '' n ← length of ST1 for i from 1 to n do t ← i-th character of ST1 + t if t = ST2 return True else return False (a) Dry run the algorithm with the following different string values of ST1 and ST2 . Give the corresponding return values. (i) ST1 = 'HONGKONG', ST2 = 'HKG' (1 mark) (ii) ST1 = 'DESSERTS', ST2 = 'STRESSED' (1 mark) (iii) ST1 = 'EARTH', ST2 = 'HEART' (1 mark) (b) What is the purpose of this algorithm? (1 mark) (c) To save memory, Jane removes the variable t from the algorithm. Describe how to modify the codes in order to achieve the same purpose of the algorithm. (2 marks) 2. A school installs some sensors in the staff room. (a) When someone enters the staff room, music is played automatically. What sensor should be used? (1 mark) (b) There is a temperature regulation system in the staff room. State what sensor should be used and describe how the sensor helps the system adjust the temperature of the staff room. (3 marks)

RkJQdWJsaXNoZXIy ODY0MTQz