---
# System prepended metadata

title: 110模擬試題

---

# 110 學年度商業類學生技藝競賽模擬題
題目出處：DOMjudge

# pA. 找出比某數⼩的最⼤質數
```python=
for _ in range(int(input())):
    n=int(input())
    for i in range(n-1,-1,-1):
        for j in range(2,int(i**0.5)+1):
            if i%j==0:
                break
        else:
            print(i)
            break
```

# pB. 給⼀個整數數字，轉為羅⾺數字符號
```python=
num = [
    [1000,'M'],
    [900,'CM'],
    [500,'D'],
    [400,'CD'],
    [100,'C'],
    [90,'XC'],
    [50,'L'],
    [40,'XL'],
    [10,'X'],
    [9,'IX'],
    [5,'V'],
    [4,'IV'],
    [1,'I']]
for _ in range(int(input())):
    n = int(input())
    ans = ''
    for i in num:
        a = divmod(n, i[0])
        if a[0]!=0:
            n = a[1]
            ans = ans + i[1]*a[0]
    print(ans)
```

# pC. 找出最⼤的數字
```python=
for _ in range(int(input())):
    print(max([int(i) for i in input().split()]))
```

# pD. 時間計算
```python=
import datetime
for _ in range(int(input())):
    N=int(input())
    n=datetime.date(1970,1,1)
    print(n+datetime.timedelta(days=N))
```

# pE. 幾A幾B
```python=
for _ in range(int(input())):
    a,b=input().split(', ')
    seen_a=[0 for _ in range(len(a))]
    seen_b=[0 for _ in range(len(b))]
    ans=[0,0] #0A0B
    for i in range(len(a)):
        if a[i]==b[i]:
            seen_a[i]=1
            seen_b[i]=1
            ans[0]+=1
    for i in range(len(a)):
        if not(seen_a[i]):
            for j in range(len(b)):
                if not(seen_b[j]):
                    if a[i]==b[j]:
                        ans[1]+=1
                        seen_a[i]=1
                        seen_b[j]=1
    print(f'{ans[0]}A{ans[1]}B')
```

# pF. ⻄洋棋
```python=
for _ in range(int(input())):
    x1,y1,x2,y2=map(int,input().split())
    dx,dy=abs(x1-x2),abs(y1-y2)
    if not(dx) and not(dy):
        print(0)
    elif dx==dy or not(dx) or not(dy):
        print(1)
    else:
        print(2)
```

# pG. 找最⼤
想法：做出節點，找出每個的根節點
```python=
d={}
for _ in range(int(input())):
    a,b=input().split('>')
    if b not in d:
        d[b]=[a]
    else:
        d[b].append(a)
D={}
def BFS(n,time):
    if n not in d or n in seen:
        if n not in D:
            D[n]=time
        else:
            D[n]=max(D[n],time)
        return
    seen.add(n)
    for i in d[n]:
        BFS(i,time+1)
for i in d:
    seen=set()
    BFS(i,0)
D=sorted(D)
if len(D)==len(d):
    print('None')
else:
    print(','.join(D))
```
WA
# pH. 印樓梯
```python=
n=int(input())
space=0
for i in range(n//2+1):
    for _ in range(n):
        print(' '*space+'*')
    if i!=n//2:
        print(' '*space+'*'*(n+1))
    space+=n
```
WA 通靈題