---
# System prepended metadata

title: 111 學年度商業類學生技藝競賽模擬題

---

# 111 學年度商業類學生技藝競賽模擬題
題目出處：[點擊](https://sci.me.ntnu.edu.tw/PortalFile/ContestData/9637/8d283925-adc6-4fa2-875e-19e92deed640.pdf)

# pA1. 內積
```python=
l1=[int(i) for i in input().split()]
l2=[int(i) for i in input().split()]
print(sum([l1[i]*l2[i] for i in range(len(l1))]))
```

# pA2. 餘數
```python=
x=int(input())
y=int(input())
x,y=min(x,y),max(x,y)
for i in range(x+1,y):
    if i%5==2 or i%5==3:
        print(i)
```

# pB1. 好朋友滿天下
```python=
d={}
for _ in range(int(input())):
    l=input().split()
    node=l[0]
    if node not in d:
        d[node]=1
    else:
        d[node]+=1
d1=sorted(d)
for i in d1:
    print(i,d[i])
```

# pB2. 四邊形
```python=
for _ in range(int(input())):
    num=[int(i) for i in input().split()]
    num.sort()
    d=set()
    for i in num:
        d.add(i)
    if len(d)==1:
        print('square')
    elif len(d)==2:
        print('rectangle')
    elif sum(num[0:3])>=num[3]:
        print('quadrangle')
    else:
        print('banana')
```
DOMjudge 內部測資有誤
# pB3. 平行四邊形
```python=
while True:
    try:
        l=[float(i) for i in input().split()]
    except:
        break
    flag=False
    for i in range(0,6,2):
        for j in range(i+2,8,2):
            if l[i]==l[j] and l[i+1]==l[j+1]:
                ans_x=sum([l[i]for i in range(0,8,2)])-l[i]*3
                ans_y=sum([l[i]for i in range(1,8,2)])-l[i+1]*3
                flag=True
                break
        if flag:
            break
        
    print('%.3f %.3f' %(ans_x,ans_y))
```

# pC1. 質數
```python=
while True:
    n=int(input())
    if not n:
        break
    ans=0
    for i in range(2, (n//2)+1):
        for j in range(2, int(i**0.5)+1):
            if i % j == 0:
                break
        else:
            i=n-i
            for x in range(2,int(i**0.5)+1):
                if i%x==0:
                    break
            else:
                ans+=1
    print(ans)
```

# pC2. 數字次數
```python=
for _ in range(int(input())):
    num=[0 for i in range(10)]
    n=int(input())
    for i in range(1,n+1):
        temp=list(str(i))
        for k in temp:
            num[int(k)]+=1
    print(*num)
```

# pC3. 加法進位
```python=
while True:
    a,b=input().split()
    if a==b=='0':
        break
    a=a[::-1]
    b=b[::-1]
    if len(a)!=len(b):
        while len(a)>len(b):
            b+='0'
        while len(b)>len(a):
            a+='0'
    ans=0
    add=0
    for i in range(len(a)):
        temp=int(a[i])+int(b[i])+add
        if temp>9:
            ans+=1
            add=1
        else:
            add=0
    if not ans:
        print('No carry operation.')
    elif ans==1:
        print('1 carry operation.')
    else:
        print('%d carry operations.' %ans)
```

# pD1. 字串
```python=
dic = [0]*26

a = input()
b = input()

for i in set(a):
    dic[ord(i)-97]+=1
for i in set(b):
    dic[ord(i)-97]+=1
M=max(dic)
for i in range(26):
    if dic[i] == M:
        print(chr(i+97),end='')

```

# pE1. 二元樹
```python=
```

# pE2. 迷宮
```python=
for _ in range(int(input())):
    n=int(input())
    m=int(input())
    arr=[]
    for _ in range(n):
        arr.append([int(i) for i in input().split()])
    for i in range(n):
        arr[i].append(10)
    arr.append([10 for i in range(m+1)])
    dp=[[0]*(m+1) for _ in range(n+1)]
    for i in range(n):
        for j in range(m):
            if i==j==0:
                dp[i][j]=arr[i][j]
            else:
                dp[i][j]=min(dp[i-1][j],dp[i+1][j],dp[i][j-1],dp[i][j+1])+arr[i][j]
    print(dp[n-1][m-1])
```
DOMjudge 內部測資有誤

# pM. 矩陣
```python=
l = list(input())
arr = []
q = 0
temp = []
num=''
for i in l:
    if q:
        if i.isdigit():
            num+=i
        elif i == ']':
            temp.append(int(num))
            num=''
            arr.append(temp)
            temp = []
            q = 0
        elif i == ',':
            temp.append(int(num))
            num=''
    else:
        if i == '[':
            q = 1
n=len(arr)
dp=[[0]*(n) for _ in range(n)]
for i in range(n):
    for j in range(n):
        dp[j][n-i-1]=arr[i][j]
ans=[]
ans.append('[')
for i in dp:
    ans.append('[')
    for j in i:
        ans.append(str(j))
        ans.append(',')
    ans.pop()
    ans+=']'
    ans+=','
ans.pop()
ans+=']'
print(''.join(ans))

```

# pT. 路徑
```python=
def DFS(n,q):
    if n not in d:
        print('->'.join(q))
    else:
        for i in d[n]:
            q.append(i)
            DFS(i,q)
            q.pop()

l=input().split(',')
l_head=1
head=0
d={}
while l_head<len(l):
    node=l[head];head+=1
    if node=='null':
        l_head+=1
        continue
    d[node]=[]
    if l[l_head]!='null':
        d[node].append(l[l_head])
    l_head+=1
    if l[l_head]!='null':
        d[node].append(l[l_head])
    l_head+=1
q=[l[0]]
DFS(l[0],q)
```
DOMjudge 內部測資有誤(no-output)