---
# System prepended metadata

title: Day3 Answer
tags: [APCS檢定營隊]

---

###### tags: `APCS檢定營隊`
# Day3 Answer
## 控制不固定數量輸入
```python=
while True:
    p = int(input())
    if p==-1:
        break
    print(p)
```
## 控制不固定數量輸入-1
```python=
while True:
    p = input()
    if p=='-1':
        break
    print(p)
```
## 控制不固定數量輸入-2
```python=
a = []
while True:
    p = input()
    if p=='-1':
        break
    a.append(p)
print(a)    
```
## 練習27
```python=
t = input()
d = input()
for i in range(int(t)):
    cmd = input()
    a,b,c = cmd.split()
    if a=='insert':
        q = d.split()
        q.insert(int(c),b)
        d = ' '.join(q)
    elif a=='replace':
        d = d.replace(b,c)
print(d)        
```
## 練習27-額外
```python=
t = input()
d = input()
for i in range(int(t)):
    cmd = input()
    a, b, c = cmd.split()
    if a == 'insert':
        q = d.split()
        q.insert(int(c), b)
        d = ' '.join(q)
    elif a == 'replace':
        d = d.replace(b, c)
    else:
        q = d.split(' ')
        for i in range(len(q)):
            if q[i] == b:
                q[i] = c
            elif q[i] == c:
                q[i] = b
        d = ' '.join(q)

print(d)
```
## 練習28
```python=
a = input()
b = input()
c = input()
d = (int(a),b,int(c))
print(d)

```
## 練習29
```python=
a = set()
a.add(3)
a.add(7)
a.remove(3)
a.add(4)
a.add(4)
print(4 in a)
print(3 in a)

```
## 練習30
```python=
a = input()
dict1 = {'S':'Spade','H':'Heart','D':'Diamond','C':'Club'}
dict2 = {'A':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'10':10,'J':11,'Q':12,'K':13}
print(dict1[a[0]],dict2[a[1:]],sep=' ')
```
## 練習34
```python=
n= int(input())
p = n//100
n %= 100
q = n//10
n %= 10
r = n//5
n %= 5
print(p,q,r,n)

```
## 練習35
```python=
def F(n):
    if n==1:
        return 1
    if n==2:
        return 9
    if n%2==0:
        return F(n/2)+3
    else:
        return F(n+1)+2
print(F(int(input())))        
```
## 練習36
```python=
def f(n):
    if n ==1 or n==2:
        return n
    return f(n-1)+f(n-2)
print(f(int(input())))    
        
```