赞
踩
# import sys
# 输入
str = input()
# 将字符串分割为数组
List = str.split(" ")
# 打印最后一个字母的长度
print(len(List[-1]))
str = input().lower()# 大写是.upper()
char = input().lower()
count = 0
for a in list(str):
if a == char:
count += 1
print(count)
def f(zifu):
if len(zifu)<8:
zifu = zifu +'0'*(8-len(zifu))
print(zifu)
else:
while len(zifu)>8:
qian8 = zifu[:8]
print(qian8)
zifu =zifu[8:]
print(zifu+'0'*(8-len(zifu)))
return zifu
a = input()
HJ5 进制转换
print(int(input(),16))
HJ6 质数因子
n = int(input())
import math
for i in range(2, int(math.sqrt(n)) + 1):
#
while n % i == 0:
print(int(i), end=' ')
n /= i
if n > 1: print(int(n), end= ' ')
HJ7 取近似值
num = float(input())
Int = int(num)
fra= num - Int
if fra >= 0.5:
print(Int+1)
else:
print(Int)
HJ8 合并表记录
amount = int(input()) #获取输入的行数 dictionary = {} #获取输入的字典 for i in range(amount): # 主体部分 input_list = list(map(int,input().split())) # 获取此行输入并分开 current_key = input_list[0] # 键 current_value = input_list[1] # 值 if current_key in dictionary: # 若字典里有此键 new_value = dictionary[current_key]+ current_value # 值相加 dictionary[current_key] = new_value else: dictionary[current_key] = current_value # 否则,存入字典 keys = list(dictionary.keys()) # 将字典从小到大排列 keys.sort() for element in keys: # 按格式输出 value = dictionary[element] print(str(element)+' '+str(value))
HJ9 提取不重复的整数
num = input()
List = list(map(int,str(num))) #将字符串变为列表
ans = []
for n in reversed(num):
if n not in ans:
ans.append(n)
res = int("".join([str(i)for i in ans]))#拼接列表成为数字*
print(res)
HJ10 字符个数统计
In = input()
num = list(map(str,In))
ans = []
for a in num:
if a not in ans:
ans.append(a)
print(len(ans))
HJ11 数字颠倒
num = list(map(int,input()))
num.reverse()
res = str("".join(str(i)for i in num))
print(res)
HJ12 字符串翻转
num = list(str(input()))
num.reverse()
ans = str("".join(i for i in num))
print(ans)
HJ13 句子逆序
In = list(map(str,input().split()))
In.reverse()
ans = ' '.join(In)
print(ans)
HJ14
n = int(input())
temp = []
for i in range(n):
temp.append(input())
temp.sort()
for i in range(n):
print(temp[i])
HJ15
num = int(input())
N = list(bin(num))
n = 0
for a in N:
if a == '1':
n+=1
print(n)
HJ21 简单密码
n = input() l = list(n) if 1 <= len(n) <=100: for i in range(len(n)): if 'a' <=n[i] <= 'z': if n[i] in 'abc': l[i] = '2' if n[i] in 'def': l[i] = '3' if n[i] in 'ghi': l[i] = '4' if n[i] in 'jkl': l[i] = '5' if n[i] in 'mno': l[i] = '6' if n[i] in 'pqrs': l[i] = '7' if n[i] in 'tuv': l[i] = '8' if n[i] in 'wxyz': l[i] = '9' elif 'A' <= n[i] <= 'Z': if n[i] == 'Z': l[i] = 'a' else: l[i] = chr(ord(n[i])+32+1) #ord()返回阿斯克码 # else: # l[i] = n[i] ans="".join(l) print(ans)
HJ22 汽水瓶
ans =[] while True: In = int(input()) temp = 0 if In == 0: break while In != 0: if In >= 3: temp += In//3 In = In//3 + In%3 elif In == 2: temp += 1 In = 0 ans.append(temp) else: In = 0 ans.append(temp) for c in ans: print(c)
HJ31 单词倒排
Str = str(input())
# 以空格和特殊符号分割字符串
ans = []
temp = []
for i,a in enumerate(Str):
if a in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
temp.append(a)
# print(a)
else:
ans.append("".join(temp))
temp=[]
ans.append("".join(temp))
ans.reverse()
print(" ".join(ans))
HJ34
Str = list(str(input()))
Str.sort()
ans = "".join(Str)
print(ans)
HJ35 蛇形矩阵
dim = input()
mat = [['0']* i for i in range(dim)]#先生成这个形状的0矩阵
jishu = 1#元素序数
for i in range(dim):
for j in range(i+1):
mat[i-j][j] = str(jishu)
jishu += 1
for i in range(dim):
print(' '.join(out[i]))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。