---
# System prepended metadata

title: k928. P5. 龍捲風圖示 (Icon)

---

# k928. P5. 龍捲風圖示 (Icon)
## 題目連結: [k928](https://zerojudge.tw/ShowProblem?problemid=k928)
## 解題想法
* `degree`儲存目前走的方向


| degree = 0 | degree = 90 | degree = 180 | degree = 270|
| -------- | -------- | -------- |--------|
| 右     | 上     | 左     |下|

* 如果下一格或下兩格已經被畫過，就轉彎；否則就往前走一格
* `moved`判斷是否原地打轉，如果是(`moved`=5)，就`break()`
## 程式碼
```python=
m,w = map(int,input().split())
table = [[0 for i in range(m)] for j in range(m)]

#start
x= y = 0
degree = 0
moved = 0
while True:
    table[x][y] = 1
    if degree == 360: degree = 0

    if degree == 0: #右
        if y+1 >= m or table[x][y+1] == 1 or (y+2<m and table[x][y+2]) == 1:
            degree += 90
        else:
            y += 1
            moved = 0
    elif degree == 90: #上
        if x-1 < 0 or table[x-1][y] == 1 or (x-2>=0 and table[x-2][y]) == 1:
            degree += 90
        else:
            x -= 1
            moved = 0
    elif degree == 180: #左
        if y-1 < 0 or table[x][y-1] == 1 or (y-2>=0 and table[x][y-2]) == 1:
            degree += 90
        else:
            y -= 1
            moved = 0
    elif degree == 270: #下
        if x+1 >= m or table[x+1][y] == 1 or (x+2<m and table[x+2][y]) == 1:
            degree += 90
        else:
            x += 1
            moved = 0
            
    moved += 1
    if moved == 5: break

#output
for i in table:
    for j in i:
        if j == 0: print(" ",end = "")
        else: print("*",end = "")
    print()
```