close
Content

你的任務是,給你一個正整數 N,判定它是否是 11 的倍數。

Input

每列資料有一個正整數N,N 最大可能到 1000 位數。

若 N = 0 代表輸入結束

Output

對每個輸入的數,輸出是否為 11 的倍數。輸出格式請參考 Sample Output。

Sample Input #1
112233
30800
2937
323455693
5038297
112234
0
Sample Output #1
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.

python:

while True:
    try:
        m=input().strip()
        if(m=='0'):break
        n=m[::-1]
        #print(n)
        odd=even=0
        for i in range(len(n)):
            if(i%2==0):even+=int(n[i])
            else:odd+=int(n[i])
        #print(odd,even)
        if(odd%11== even%11):print(f'{m} is a multiple of 11.')
        else:print(f'{m} is not a multiple of 11.')
    except:
        break
arrow
arrow
    創作者介紹
    創作者 趴趴熊日常 的頭像
    趴趴熊日常

    資工趴趴熊的小天地

    趴趴熊日常 發表在 痞客邦 留言(0) 人氣()