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

新南威尔士大学COMP9021 QUIZ3课业解析
题意:
按照移动规则进行移动,规则是0-7的数字为从北开始的顺时针的八个方向,每移动到一个位置,将该位置的开关反转(on变成off,off变成on),然后进行下一次的移动,初始条件是原点的开关为on,其他所有位置为off。
解析:
先将输入的十进制整数转换为八进制,如果输入是由0开始的,则保留0。随后按照转换的八进制数字,从左向右的移动,每次移动,对移动到的位置的开关状态进行改变,最后保留为上下左右四个最远方向的状态为on的点的矩形。如测试案例,3654转换为八进制为7106,向下为正北方向,白点为on,黑点为off,每次移动过后都以新的点为起始点
在这里插入图片描述
左上角白点为起始点,7106,就是右下,左下,向下,向右的移动轨迹,经过的点变为on状态,取出这个所有on状态的最小的矩形输出即可
涉及知识点:
python列表
更多可加微信讨论
微信号:wanqcwanqcwanqc0219
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.
2 COMP9021 PRINCIPLES OF PROGRAMMING
$ python3 quiz_3.py
Enter a non-strictly negative integer: 100738324
Keeping leading 0’s, if any, in base 8, 100738324 reads as 600222424.
⚪⚫⚫⚪⚪
⚪⚪⚫⚫⚪
⚫⚪⚪⚪⚪
$ python3 quiz_3.py
Enter a non-strictly negative integer: 73776
Keeping leading 0’s, if any, in base 8, 73776 reads as 220060.
⚪⚪⚪
⚪⚫⚫
⚪⚪⚫
⚫⚪⚫
$ python3 quiz_3.py
Enter a non-strictly negative integer: 7704322
Keeping leading 0’s, if any, in base 8, 7704322 reads as 35307402.
⚪⚫
⚪⚫
⚫⚫
⚫⚪
$ python3 quiz_3.py
Enter a non-strictly negative integer: 206537612
Keeping leading 0’s, if any, in base 8, 206537612 reads as 1423701614.
⚪⚫⚫⚫
⚫⚫⚪⚪
⚫⚪⚪⚫
⚫⚪⚫⚫
⚪⚫⚫⚫
$ python3 quiz_3.py
Enter a non-strictly negative integer: 000123456789
Keeping leading 0’s, if any, in base 8, 000123456789 reads as 000726746425.
⚪⚫⚫⚫
⚪⚫⚫⚫
⚪⚫⚫⚪
⚪⚫⚪⚪
⚪⚫⚪⚪
⚫⚫⚪⚫

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