第1題 字符串最後一個單詞的長度python
a = input().split(" ") print(len(a[-1]))
第2題 計算字符個數app
a = input() b = input() print(a.lower().count(b.lower()))
第3題 明明的隨機數code
while True: try: num = int(input()) data = [] for i in range(num): data.append(int(input())) data = list(set(data)) data = sorted(data) for i in data: print(i) except: break
第4題 字符串分隔內存
def stringSplit(s): while len(s)>8: print(s[0:8]) s = s[8:len(s)] print(s+(8-len(s))*'0') stringSplit(input()) stringSplit(input())
第5題 進制轉換字符串
while True: try: print(str(int(input(),16))) except: break
第6題 質數因子input
def primeFactor(a): res = [] while a>1: for i in range(2,a+1): if a%i == 0: res.append(i) a = int(a/i) break return res a = primeFactor(int(input())) for i in a: print(i,end=" ")
第7題 取近似值string
def myround(a): if 10*a%10>=5: return int(a)+1 else: return int(a) print(myround(float(input())))
第8題 合併表記錄it
a = input() d = {} for i in range(int(a)): b = list(map(int, input().split(' '))) if b[0] not in d.keys(): d[b[0]] = b[1] else: d[b[0]] += b[1] for key in d.keys(): print(key, d[key])
第9題 提取不重複的整數class
a = input() s = '' for i in range(len(a)-1,-1,-1): if a[i] not in s: s += a[i] print(s)
第10題 字符個數統計隨機數
s = input() a = [] for i in s: if 0 <= ord(i) <= 127 and i not in a: a.append(i) print(len(a))
s = input() d = {} for i in s: if 0 <= ord(i) <= 127: d[i] = 1 print(sum(d.values()))
第11題 數字顛倒
a = input() b = '' for i in a[::-1]: b += i print(b)
第12題 字符串反轉
a = input().split(' ') print(' '.join(a[::-1]))
第13題 句子逆序
a = int(input()) b = [] for i in range(a): b.append(input()) for i in sorted(b): print(i)
第14題 字串的鏈接最長路徑查找
a = int(input()) b = [] for i in range(a): b.append(input()) for i in sorted(b): print(i)
第15題 求int型數據在內存中存儲時1的個數
print(bin(int(input())).count('1'))
未完待續……