首页
题库
公司真题
专项练习
面试题库
在线编程
面试
面试经验
AI 模拟面试
简历
求职
学习
课程
专栏·文章
竞赛
搜索
我要招人
发布职位
发布职位、邀约牛人
更多企业解决方案
在线笔面试、雇主品牌宣传
登录
/
注册
LHP-HIT
获赞
3
粉丝
0
关注
1
看过 TA
36
男
National University of Singapore
2024
自动化
IP属地:江苏
暂未填写个人简介
私信
关注
拉黑
举报
举报
确定要拉黑LHP-HIT吗?
发布(21)
刷题
LHP-HIT
2023-11-01 11:20
National University of Singapore 电气类
题解 | #迷宫问题#
def findMazePath(maps): if not maps or not maps[0]: return 0 rows, cols = len(maps), len(maps[0]) directions = [(-1, 0), (0, -1), (1, 0), (0, 1)] # 记录已经访问过的单元格 visited = [[False for _ in range(cols)] for _ in range(rows)] path = [] def dfs(i, j): # 若为...
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-31 15:40
National University of Singapore 电气类
题解 | #24点游戏算法#
def judgePoint24(num): e = 1e-6 def operate(x, y): return [x+y, x-y, x*y] + ([x/y] if y - 0 > e else []) + ([y/x] if x - 0 > e else []) def dfs(num): # 若只剩一个数字,判断是否为24 if len(num) == 1: return abs(num[0] - 24) < e n = len(num) ...
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-27 10:53
National University of Singapore 电气类
题解 | #图片整理#
arr = input() arr = sorted(arr) print(''.join(str(x) for x in arr))
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-27 10:48
National University of Singapore 电气类
题解 | #单词倒排#
import re arr = input() lst = [] for x in arr: if re.search(r'[a-zA-Z]', x): continue else: arr = arr.replace(x, ' ') #单词间隔符以一个空格 arr = arr.split()[::-1] #先以空格分开单词,再倒序 print(' '.join(str(x) for x in arr))
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-26 19:26
National University of Singapore 电气类
题解 | #字符串合并处理#
import re str1, str2 = list(input().split()) str_all = list(str1 + str2) str_all[::2] = sorted(str_all[::2]) #奇数位排序 str_all[1::2] = sorted(str_all[1::2]) #偶数位排序 result = "" for n in str_all: if re.search(r'[0-9A-Fa-f]', n): # 如果字符在特殊字符范围内 n = bin(int(n, 16))[2:].rjust(4, '0')...
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-26 17:02
National University of Singapore 电气类
题解 | #成绩排序#
n = int(input()) mode = int(input()) score_list = [] for i in range(n): name, score = input().split() score = int(score) score_list.append((i, name, score)) if mode == 1: result = sorted(score_list, key=lambda x : x[2]) #主要是sorted函数用法 if mode == 0: result = sorted(score_list, ke...
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-24 14:26
National University of Singapore 电气类
题解 | #字符串通配符#
import re #导入了Python的正则表达式模块 a = input().lower() #转为小写 b = input().lower() a = a.replace('?','[a-z0-9]').replace('*','[a-z0-9]*') #替换‘?’和‘*’ if b in re.findall(a,b): #返回一个列表,包含所有与模式 a 匹配的子串 print('true') else: print('false')
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-23 15:34
National University of Singapore 电气类
题解 | #明明的随机数#
n = int(input()) arr = [] for _ in range(n): arr.append(int(input())) arr = set(arr) #去重,打乱排序 arr = list(arr) #转为list列表 arr.sort() #列表排序 for i in arr: print(i)
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-23 14:47
National University of Singapore 电气类
题解 | #记负均正II#
注意输入的处理,使用while True。 p_arr = [] n_arr = [] while True: try: i = int(input()) if i >= 0: p_arr.append(i) else: n_arr.append(i) except: break print(len(n_arr)) if len(p_arr) != 0: print(format(sum(p_arr)/len(p_arr), '.1f')) else...
0
点赞
评论
收藏
转发
LHP-HIT
2023-10-23 14:29
National University of Singapore 电气类
题解 | #记负均正#
n = int(input()) nums = map(int, input().split()) positive_sum = 0.0 positive_num = 0 negative_num = 0 for num in nums: if num < 0: negative_num += 1 elif num > 0: positive_sum += num positive_num += 1 if positive_num != 0: positive_avg = round(positive_s...
0
点赞
评论
收藏
转发
LHP-HIT
2023-09-14 11:22
National University of Singapore 电气类
题解 | #求int型正整数在内存中存储时1的个数#
m = int(input()) n = bin(m) #十进制转二进制 n = list(n) #转成list count = 0 for i in n: if i == '1': count += 1 print(count) 注意bin()的用法,十进制转二进制。
0
点赞
评论
收藏
转发
LHP-HIT
2023-09-13 15:38
National University of Singapore 电气类
题解 | #字符串排序#
n = int(input()) array = [] for i in range(n): array.append(input()) #这里不能直接用array[i]索引 print("\n".join(sorted(array))) #这个print方法经常用
0
点赞
评论
收藏
转发
LHP-HIT
2023-09-13 15:23
National University of Singapore 电气类
题解 | #句子逆序#
arr = input().split() arr = list(arr) arr2 = arr[::-1] for word in arr2: print(word, end = ' ') 依旧运用list的切片方法。
0
点赞
评论
收藏
转发
LHP-HIT
2023-09-13 14:06
National University of Singapore 电气类
题解 | #字符串反转#
x = input() print(x[::-1])
0
点赞
评论
收藏
转发
LHP-HIT
2023-09-13 14:07
已编辑
National University of Singapore 电气类
题解 | #数字颠倒#
x = input() print(x[::-1]) 运用字符串、列表的切片特性,x[::-1]。注意不需要将输入转成int形式,题目要求以字符串形式输出。
0
点赞
评论
收藏
转发
1
2
工具箱
TA的圈子
暂未加入圈子
TA的圈子
TA的笔记
暂无笔记
TA的笔记
登录
0
天
已登录
0
天
连续登录
0
人
今日访客
牛客网
牛客企业服务