Skip to content

Commit fe4c03a

Browse files
committed
add huawei quiz
1 parent b7195ee commit fe4c03a

File tree

7 files changed

+84
-0
lines changed

7 files changed

+84
-0
lines changed

Diff for: huawei/j1.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
str = input('please input ')
2+
count = 0
3+
for i in reversed(str):
4+
if i == ' ':
5+
break
6+
count += 1
7+
8+
print(count)

Diff for: huawei/j2.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
str = input()
2+
c = input()
3+
target = []
4+
if ord(c) >= ord('a') and ord(c) <= ord('z'):
5+
target = [ c, chr(ord(c) - 32)]
6+
elif ord(c) >= ord('A') and ord(c) <= ord('Z'):
7+
target = [ c, chr(ord(c) + 32)]
8+
else:
9+
target = [c]
10+
11+
count = 0
12+
for i in str:
13+
if i in target:
14+
count += 1
15+
16+
print(count)

Diff for: huawei/j3.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
n = input()
2+
target = []
3+
for i in range(int(n)):
4+
target.append(input())
5+
6+
t = list(map(lambda x : int(x) , target))
7+
unique_t = set(t)
8+
# print('result:')
9+
for i in sorted(unique_t):
10+
print(i)

Diff for: huawei/j4.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
str = input()
2+
if not str:
3+
exit()
4+
result = []
5+
# range 和 slice 都是属于含头不含尾
6+
for i in range(0, len(str) , 8):
7+
if i + 8 > len(str) -1 :
8+
s = str[i : len(str)] + '0'*( 8 - (len(str) - i ))
9+
else:
10+
s = str[i:i+8]
11+
result.append(s)
12+
for i in result:
13+
print(i)
14+

Diff for: huawei/j5.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hex_num = input()
2+
dec_num = int(hex_num , 16)
3+
print(dec_num)

Diff for: huawei/j6.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
num = int(input())
2+
3+
factors = []
4+
divisor = 2
5+
6+
while divisor * divisor <= num :
7+
if num % divisor == 0:
8+
factors.append(divisor)
9+
num = num // divisor
10+
else:
11+
if divisor == 2:
12+
divisor = 3
13+
else:
14+
divisor += 2
15+
if num > 1:
16+
factors.append(num)
17+
18+
19+
print(" ".join(map(str, factors)))

Diff for: huawei/j7.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
num = int(input())
2+
d = {}
3+
for i in range(num):
4+
aa , bb = input().split()
5+
a , b = int(aa), int(bb)
6+
if a in d:
7+
d[a] = d[a] + b
8+
else:
9+
d[a] = b
10+
11+
## 对字典排序的方式。
12+
d = dict(sorted(d.items()))
13+
for i , j in d.items():
14+
print(i ,j)

0 commit comments

Comments
 (0)