文档内容
华为笔试题共3道编程题。第一题100分,第二题200分,第三题300分,一共600分。
第一题:
输入描述:
1、忽略小数点,例如“A1.2”,认为包含整数1和2;
2、如果整数的左侧出现“-”,则奇数个数认为是负整数,偶数个数认为是正整数。例如
AB-1CD--2EF---3“”,认为包含整数-1、2和-3。
输出描述:
输出即为字符串中所有整数数字之和。
#coding=utf-8
import sys
if __name__ == "__main__":
def sum_of_int(s):
sums, num, pos = 0, 0, 1
if s == None:
return 0
for i in range(len(s)):
if 48 <= ord(s[i]) <= 57:
num = num * 10 + int(s[i])*pos
else:
sums += num
num = 0
if s[i] == '-':
if i-1 > -1 and s[i-1] == '-':
pos = -pos
else:
pos = -1
else:
pos = 1
sums=sums+num
return sums
e=sys.stdin.readline().strip()
result=sum_of_int(e)
print (result)
第二题:多项式卷积乘法
C(n) = A(n)*B(n)多项式系数[b(2) b(1) b(0)] = [1 2 5]
[c(3) c(2) c(1) c(0)] = [1 3 7 5]
c(0) = a(0)b(0)
c(1) = a(0)b(1)+a(1)b(0)
c(2)=a(0)b(2)+a(1)b(1)+a(2)b(0)
c(3)=a(0)b(3)+a(1)b(2)+a(2)b(1)+a(3)b(0)
其中 :a(3)=a(2)=b(3=0)
#coding=utf-8
def juanji():
a_xishu=[]
b_xishu=[]
for i in range(5):
one=[]
one.append(int(input()))
one.append(int(input()))
a_xishu.append(one)
for i in range(5):
two=[]
two.append(int(input()))
two.append(int(input()))
b_xishu.append(two)
a_xishu=a_xishu[::-1]
b_xishu = b_xishu[::-1]
a_len=len(a_xishu)
b_len=len(b_xishu)
for i in range(9)[::-1]:
ci_s=0
ci_x=0
for index in range(i+1)[::-1]:
if i-index