707 共同科目
x = set()
y = set()
print("Enter group X's subjects:")
while True:
enter = input().strip()
if enter == "end":
break
x.add(enter)
print("Enter group Y's subjects:")
while True:
enter = input().strip()
if enter == "end":
break
y.add(enter)
print(sorted(x|y)) # 所有
print(sorted(x&y)) # 共有
print(sorted(y-x)) # Y有,X沒有
print(sorted(x^y)) # X,Y彼此沒有
APCS-2017-10-28-1-邏輯運算子
while True:
try:
a, b, c = map(int, input().split())
if a != 0:
a = 1
if b != 0:
b = 1
if c == 0:
c = False
else:
c = True
flag = False
if (a and b) == c:
print('AND')
flag = True
if (a or b) == c:
print('OR')
flag = True
if (a != b) == c:
print('XOR')
flag = True
if not flag:
print('IMPOSSIBLE')
except:
break
APCS-2017-03-04-1-秘密差
while True:
try:
a = 0
b = 0
numstr = input().strip()
for i in range(len(numstr)):
if i%2 == 0:
a += int(numstr[i])
else:
b += int(numstr[i])
print(abs(a-b))
except:
break
參考資料:
TQC+ Python 3
瑋哥
Yui Huang
Yui Huang