Skip to content

Commit f74220d

Browse files
committed
feat: 添加多个新的算法题实现,包括字符串最后一个单词长度、字符出现次数、朋友们的喜好和密码游戏
1 parent fbb99ff commit f74220d

4 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @nc app=nowcoder id=8c949ea5f36f422594b306a2300315da topic=37 question=21224 lang=Python3
2+
# 2026-04-26 19:40:38
3+
# https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da?tpId=37&tqId=21224
4+
# [HJ1] 字符串最后一个单词的长度
5+
6+
# @nc code=start
7+
8+
9+
a = input().split()
10+
print(len(a[-1]))
11+
12+
13+
# @nc code=end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-26 19:45:14
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-26 20:10:59
6+
'''
7+
# @nc app=nowcoder id=a35ce98431874e3a820dbe4b2d0508b1 topic=37 question=21225 lang=Python3
8+
# 2026-04-26 19:45:14
9+
# https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&tqId=21225
10+
# [HJ2] 计算某字符出现次数
11+
12+
# @nc code=start
13+
14+
import sys, math
15+
from collections import deque, defaultdict, Counter
16+
import heapq, bisect
17+
input = lambda: sys.stdin.readline().rstrip()
18+
19+
def solve():
20+
s = input().lower()
21+
c = input().lower()
22+
cnt = {}
23+
print(s.count(c))
24+
25+
if __name__ == "__main__":
26+
t = 1
27+
# t = int(input())
28+
for _ in range(t):
29+
solve()
30+
31+
32+
# @nc code=end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-26 20:13:26
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-26 20:15:05
6+
'''
7+
# @nc app=nowcoder id=c62ef46892ef4c478802df983f8624b7 topic=314 question=2549745 lang=Python3
8+
# 2026-04-26 20:13:26
9+
# https://www.nowcoder.com/practice/c62ef46892ef4c478802df983f8624b7?tpId=314&tqId=2549745
10+
# [NP27] 朋友们的喜好
11+
12+
# @nc code=start
13+
14+
import sys, math
15+
from collections import deque, defaultdict, Counter
16+
import heapq, bisect
17+
input = lambda: sys.stdin.readline().rstrip()
18+
19+
def solve():
20+
res = []
21+
name = ['Niumei', 'YOLO', 'Niu Ke Le', 'Mona']
22+
food = ['pizza', 'fish', 'potato', 'beef']
23+
nums = [3, 6, 0, 3]
24+
25+
res.append(name)
26+
res.append(food)
27+
res.append(nums)
28+
29+
print(res)
30+
31+
if __name__ == "__main__":
32+
t = 1
33+
# t = int(input())
34+
for _ in range(t):
35+
solve()
36+
37+
38+
# @nc code=end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-26 20:15:54
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-26 20:16:05
6+
'''
7+
# @nc app=nowcoder id=36641ab168664384aff798ba7ce34bc1 topic=314 question=2583410 lang=Python3
8+
# 2026-04-26 20:15:54
9+
# https://www.nowcoder.com/practice/36641ab168664384aff798ba7ce34bc1?tpId=314&tqId=2583410
10+
# [NP28] 密码游戏
11+
12+
# @nc code=start
13+
14+
import sys, math
15+
from collections import deque, defaultdict, Counter
16+
import heapq, bisect
17+
input = lambda: sys.stdin.readline().rstrip()
18+
19+
def solve():
20+
s = input().strip()
21+
a = [str((int(c) + 3)%9) for c in s]
22+
a[0],a[2] = a[2],a[0]
23+
a[3],a[1] = a[1],a[3]
24+
25+
print("".join(a))
26+
27+
28+
29+
if __name__ == "__main__":
30+
t = 1
31+
# t = int(input())
32+
for _ in range(t):
33+
solve()
34+
35+
36+
# @nc code=end

0 commit comments

Comments
 (0)