参考:
链接:https://www.nowcoder.com/discuss/469292?
第一题
判断两个字符串的最长公共子串,比如ABCDEF和AUBWCD的最长公共子串为ABCD,长度为4,要求判断子串和原字符串长度之比(四舍五入2位小数),当公共子串长度未达到原子串长度的50%,输出Yes,否则输出No。
输入:
6
ABCDEF
AUBWCD
输出:
0.67 No
参考leetcode第1143题
#第一题
n=int(input())
a1=list(input().split())
a2=list(input().split())
dp=[[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,n+1):
if a1[i-1]==a2[j-1]:
dp[i][j]=dp[i-1][j-1]+1
else:
dp[i][j]=max(dp[i][j-1],dp[i-1][j])
res=round((dp[-1][-1]/n)*100)/100
if res<=0.5:
print('%.2f'%res,'Yes')
else:
print('%.2f'%res,'No')
第二题
输入两个数字,判断两个数字之间多少个去除一个数字后依然是回文数字的素数。
输入:110 120
输出:10
分析:110去除0之后为11,既是素数,又可以回文(从左到右和从右到左数字顺序相同),111去除1后为11,112去除2以后为11,以此类推到119去除9后为11,120去除任何一个数字都不是素数,所以从110-120一共10个数字满足条件。
count = 0
list_sushu = {2, 3, 5, 7, 11, 101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929, 10301, 10501, 10601, 11311, 11411, 12421, 12721, 12821, 13331, 13831, 13931, 14341, 14741, 15451, 15551, 16061, 16361, 16561, 16661, 17471, 17971, 18181, 18481, 19391, 19891, 19991, 30103, 30203, 30403, 30703, 30803, 31013, 31513, 32323, 32423, 33533, 34543, 34843, 35053, 35153, 35353, 35753, 36263, 36563, 37273, 37573, 38083, 38183, 38783, 39293, 70207, 70507, 70607, 71317, 71917, 72227, 72727, 73037, 73237, 73637, 74047, 74747, 75557, 76367, 76667, 77377, 77477, 77977, 78487, 78787, 78887, 79397, 79697, 79997, 90709, 91019, 93139, 93239, 93739, 94049, 94349, 94649, 94849, 94949, 95959, 96269, 96469, 96769, 97379, 97579, 97879, 98389, 98689}
N,M = list(map(int, input().split()))
for i in range(N,M+1):
ss = str(i)
for i in range(len(ss)):
sss = ss[:i]+ss[i+1:]
if sss == '':
break
num = int(sss)
if num in list_sushu:
count+=1
break
print(count)