2017年12月23日 星期六

a038: 公平的戰役(0尾版)

a038: 公平的戰役(0尾版)
'''
輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。
最後一組 A=0、B=0 代表輸入結束,不用對這組資料做處理。

輸出說明:
依照每一組資料,輸出哪一方(A 或 B)必須撤兵,
以及要撤出多少兵力,才能使兩方的兵力相等,
如果兩方原本的兵力就相同,則請輸出 0,每組資料輸出完請換行。

範例輸入: 
100 150
160 100
0 0

範例輸出 :
B 50
A 60
'''
A=[]
B=[]

print("輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。")
print("最後一組 A=0、B=0 代表輸入結束,不用對這組資料做處理。")

while True :
    print(" A、B 需以逗號隔開 > ",end="")
    A1, B1  = map(int,input().split(','))
    if A1==0 and B1==0 :
        break
    else:
        A.append(A1)
        B.append(B1)
     

print(A,B)
for i in range(0,len(A)):
    if A[i] > B[i]:
        print("A需撤兵",A[i]-B[i])
    elif B[i] > A[i]:
        print("B需撤兵",B[i]-A[i])
    else:
        print("A,B 兵力相同")


====== ==== RESTART: F:/Python_APSC/a038.py ======================
輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。
最後一組 A=0、B=0 代表輸入結束,不用對這組資料做處理。
 A、B 需以逗號隔開 > 12,34
 A、B 需以逗號隔開 > 43,54
 A、B 需以逗號隔開 > 56,76
 A、B 需以逗號隔開 > 0,111
 A、B 需以逗號隔開 > 1234,666
 A、B 需以逗號隔開 > 0,0
[12, 43, 56, 0, 1234] [34, 54, 76, 111, 666]
B需撤兵 22
B需撤兵 11
B需撤兵 20
B需撤兵 111
A需撤兵 568
>>> 

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...