简单题

1.HJ12字符串反转

2.HJ11数字颠倒

print(''.join(reversed(input())))

3.HJ54表达式求积

print(int(eval(input()))) # eval表达式求值

4.HJ106字符逆序

5.HJ76尼科彻斯定力

6.HJ75公共子串计算


from operator import le
# awaabb
# aawbb

def solution(s1, s2):
    maxlen = 0
    if len(s1) >len(s2):
        s1,s2 = s2,s1  # s1为较小的那个字符串
    for i in range(len(s1)): # 0,1,2,3....
        for j in range(i,len(s1)): # 
              if s1[i:j+1] in s2 and j+1 -i >maxlen: # s1截的所有子串,在s2匹配,并更新当前的最大值
                maxlen =  j+1-i
    return maxlen
s = input()
t = input()
print(solution(s,t))

7.HJ86求最大连续bit数

data = int(input())
binary = '{:b}'.format(data) #11001000
data3 = [len(i) for i in binary.split('0')]
print(max(data3))

8.HJ85最长回文子串


while True:
    try:
        s = input()
        res = []

        for i in range(len(s)):
            for j in range(i + 1, len(s) + 1):
                if s[i:j] == s[i:j][::-1]:
                    res.append(j - i)
        if res != "":
            print(max(res))
    except:
        break

9.HJ100等差数列


n = int(input())
result = [i  for i in range(2,3*n+2,3)] # 3*n+2最后一位
print(sum(result))

10.HJ87密码强度等级


while True:
    try:
        s = input()
        sc = 0
        # 密码长度
        if len(s) <= 4:
            sc = sc + 5
        elif len(s) <= 7:
            sc = sc + 10
        else:
            sc = sc + 25

        # 字母
        isu = 0
        isl = 0
        for i in s:
            if i.isupper():
                isu = 1
                break
        for i in s:
            if i.islower():
                isl = 1
                break
        sc = sc + 10 * (isu + isl)

        # 数字
        shu = "0123456789"
        count1 = 0
        for i in s:
            if i in shu:
                count1 = count1 + 1
        if count1 == 1:
            sc = sc + 10
        elif count1 > 1:
            sc = sc + 20
        else:
            sc = sc

        # 符号
        fh = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
        count2 = 0
        for i in s:
            if i in fh:
                count2 = count2 + 1
        if count2 == 1:
            sc = sc + 10
        elif count2 > 1:
            sc = sc + 25
        else:
            sc = sc

        # 奖励
        if isu + isl == 2 and count1 >= 1 and count2 >= 1:
            sc = sc + 5
        elif isu + isl > 1 and count1 >= 1 and count2 >= 1:
            sc = sc + 3
        elif isu + isl > 1 and count1 >= 1:
            sc = sc + 2
        if sc >= 90:
            print("VERY_SECURE")
        elif sc >= 80:
            print("SECURE")
        elif sc >= 70:
            print("VERY_STRONG")
        elif sc >= 60:
            print("STRONG")
        elif sc >= 50:
            print("AVERAGE")
        elif sc >= 25:
            print("WEAK")
        elif sc >= 0:
            print("VERY_WEAK")
    except:
        break

中等题

1.HJ10字符个数统计

print(len(set(input().replace('\n',''))))

2.HJ46截取字符串


data = input()
k = int(input())
print(data[:k])

3.HJ60查找组成一个偶数最接近的两个素数



def isSuShu(n):
    if n<=2:
        return True
    else:
        for i in range(2,n):
            if n % i ==0:
                return False
        else:
            return True
            

data  = int(input())
for i in range(int(data / 2), data):
    if isSuShu(i) and isSuShu(data-i):
        print(data-i)
        print(i)
        break

4.HJ40统计字符


data = input()

a = 0 # 空格
b = 0 # 数字
c = 0 # 其他
d = 0 # 字母

for i in data:
    tmp = ord(i)
    if tmp == 32:
        a+=1 # 空格
    elif 48 <=tmp <=57:
        b+=1 # 数字
    elif 65 <=tmp <=90 or 97 <=tmp <=122:
        d+=1  # 字母
    else:
        c +=1 

print(d)
print(a)
print(b)
print(c)

5.HJ14字符串排序


num = int(input())
stack = []
for i in range(num):
    stack.append(input())
print("\n".join(sorted(stack)))

6.HJ5进制转换


data = input()
print(int(data,16))  # 16进制转10进制, int(xxx,16)  hex:10进制转成16进制
 

7.HJ59找出字符串中第一个只出现一次的字符


# 方法1: Counter
from collections import Counter

data = input()
result = -1
c = Counter(data)
for i,v in c.items():
    if v == 1:
        result = i
        break
print(result)

# 方法2: s.count(i)
s = input()
for i in s:
    if s.count(i) == 1:
        print(i)
        break
else:
    print('-1')

8.HJ58输入n个整数,输出其中最小的K个


n, k = list(map(int, input().split()))
num = list(map(int, input().split()))
num = sorted(num)
for i in num[:k]:
    print(i, end=" ")

9.HJ81字符串字符匹配

s1 = set(input())
s2 = set(input())

if set(s1) & set(s2) == set(s2):
    print('true')
else:
    print('false')

__END__