新南威尔士大学COMP9021 QUIZ3课业解析

题意:

按照移动规则进行移动,规则是0-7的数字为从北开始的顺时针的八个方向,每移动到一个位置,将该位置的开关反转(on变成off,off变成on),然后进行下一次的移动,初始条件是原点的开关为on,其他所有位置为off。 

解析:

先将输入的十进制整数转换为八进制,如果输入是由0开始的,则保留0。随后按照转换的八进制数字,从左向右的移动,每次移动,对移动到的位置的开关状态进行改变,最后保留为上下左右四个最远方向的状态为on的点的矩形。如测试案例,3654转换为八进制为7106,向下为正北方向,白点为on,黑点为off,每次移动过后都以新的点为起始点


左上角白点为起始点,7106,就是右下,左下,向下,向右的移动轨迹,经过的点变为on状态,取出这个所有on状态的最小的矩形输出即可

涉及知识点:

python列表

更多可加微信讨论

微信号:tiamo-0620

pdf

QUIZ 3

COMP9021 PRINCIPLES OF PROGRAMMING

Reading the number written in base 8 from right to left, keeping the leading 0’s, if any:

0: Move North

1: Move North-East

2: Move East

3: Move South-East

4: Move South

5: Move South West

6: Move West

7: Move North-West

We start from a position that is the unique position where the switch is on.

Moving to a position switches on to off, off to on there.

$ python3 quiz_3.py

Enter a non-strictly negative integer: 0

Keeping leading 0's, if any, in base 8, 0 reads as 0.

⚪ ⚪$

python3 quiz_3.py

Enter a non-strictly negative integer: 00

Keeping leading 0's, if any, in base 8, 00 reads as 00.

⚪ ⚪ ⚪$

python3 quiz_3.py

Enter a non-strictly negative integer: 0256

Keeping leading 0's, if any, in base 8, 0256 reads as 0400.

⚪$

python3 quiz_3.py

Enter a non-strictly negative integer: 032

Keeping leading 0's, if any, in base 8, 032 reads as 040.

$ python3 quiz_3.py

Enter a non-strictly negative integer: 3654

Keeping leading 0's, if any, in base 8, 3654 reads as 7106.

⚪⚫

⚫⚪

⚪⚫

⚪⚪

Date: Term 3, 2019.


你可能感兴趣的:(新南威尔士大学COMP9021 QUIZ3课业解析)