Skip to content

Commit e666f32

Browse files
committed
feat: 添加多个算法题实现,包括用列表实现栈、队列、团队分组、加减器、逻辑运算等
1 parent f1ca5e1 commit e666f32

17 files changed

Lines changed: 572 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:42:21
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:42:26
6+
'''
7+
# @nc app=nowcoder id=38187b9f30e44fdaa496751b82b0adbf topic=314 question=10055869 lang=Python3
8+
# 2026-04-27 07:42:21
9+
# https://www.nowcoder.com/practice/38187b9f30e44fdaa496751b82b0adbf?tpId=314&tqId=10055869
10+
# [NP29] 用列表实现栈
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+
stack = [1, 2, 3, 4, 5]
21+
stack.pop()
22+
print(stack)
23+
stack.pop()
24+
print(stack)
25+
x = int(input())
26+
stack.append(x)
27+
print(stack)
28+
29+
if __name__ == "__main__":
30+
sys.setrecursionlimit(10**7)
31+
t = 1
32+
# t = int(input())
33+
for _ in range(t):
34+
solve()
35+
36+
37+
# @nc code=end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:44:20
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:45:54
6+
'''
7+
# @nc app=nowcoder id=cc9e56e0d80d44e5990f76196adb4912 topic=314 question=10055870 lang=Python3
8+
# 2026-04-27 07:44:20
9+
# https://www.nowcoder.com/practice/cc9e56e0d80d44e5990f76196adb4912?tpId=314&tqId=10055870
10+
# [NP30] 用列表实现队列
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+
queue = [1, 2, 3, 4, 5]
21+
queue.pop(0)
22+
print(queue)
23+
queue.pop(0)
24+
print(queue)
25+
x = int(input())
26+
queue.append(x)
27+
print(queue)
28+
29+
if __name__ == "__main__":
30+
sys.setrecursionlimit(10**7)
31+
t = 1
32+
# t = int(input())
33+
for _ in range(t):
34+
solve()
35+
36+
37+
# @nc code=end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:46:30
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:46:43
6+
'''
7+
# @nc app=nowcoder id=113a0507b1144fa9a602c2a3cd847205 topic=314 question=2367361 lang=Python3
8+
# 2026-04-27 07:46:30
9+
# https://www.nowcoder.com/practice/113a0507b1144fa9a602c2a3cd847205?tpId=314&tqId=2367361
10+
# [NP31] 团队分组
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+
group_list = [ 'Tom', 'Allen', 'Jane', 'William', 'Tony' ]
21+
print(group_list[:2])
22+
print(group_list[1:4])
23+
print(group_list[-2:])
24+
25+
if __name__ == "__main__":
26+
sys.setrecursionlimit(10**7)
27+
t = 1
28+
# t = int(input())
29+
for _ in range(t):
30+
solve()
31+
32+
33+
# @nc code=end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:49:07
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:49:11
6+
'''
7+
# @nc app=nowcoder id=13e575e3bd4b4ed0aba7be2fa1efcb3f topic=314 question=10055874 lang=Python3
8+
# 2026-04-27 07:49:07
9+
# https://www.nowcoder.com/practice/13e575e3bd4b4ed0aba7be2fa1efcb3f?tpId=314&tqId=10055874
10+
# [NP32] 牛牛的加减器
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+
x = int(input())
21+
y = int(input())
22+
23+
print(x+y)
24+
print(x-y)
25+
26+
if __name__ == "__main__":
27+
sys.setrecursionlimit(10**7)
28+
t = 1
29+
# t = int(input())
30+
for _ in range(t):
31+
solve()
32+
33+
34+
# @nc code=end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:49:51
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:49:56
6+
'''
7+
# @nc app=nowcoder id=2b0e586dfdbe4da4aabccbc94a4f7224 topic=314 question=10055875 lang=Python3
8+
# 2026-04-27 07:49:51
9+
# https://www.nowcoder.com/practice/2b0e586dfdbe4da4aabccbc94a4f7224?tpId=314&tqId=10055875
10+
# [NP33] 乘法与幂运算
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+
x = int(input())
21+
y = int(input())
22+
23+
print(x*y)
24+
print(x**y)
25+
26+
if __name__ == "__main__":
27+
sys.setrecursionlimit(10**7)
28+
t = 1
29+
# t = int(input())
30+
for _ in range(t):
31+
solve()
32+
33+
34+
# @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-27 07:51:38
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:53:46
6+
'''
7+
# @nc app=nowcoder id=9fe22ac9e55448f4920886f84efeac58 topic=314 question=10055876 lang=Python3
8+
# 2026-04-27 07:51:38
9+
# https://www.nowcoder.com/practice/9fe22ac9e55448f4920886f84efeac58?tpId=314&tqId=10055876
10+
# [NP34] 除法与取模运算
11+
12+
# @nc code=start
13+
14+
15+
import sys, math
16+
from collections import deque, defaultdict, Counter
17+
import heapq, bisect
18+
input = lambda: sys.stdin.readline().rstrip()
19+
20+
def solve():
21+
x = int(input())
22+
y = int(input())
23+
24+
if y != 0:
25+
print(f"{x//y} {x%y}")
26+
print(f"{x/y:.2f}")
27+
28+
if __name__ == "__main__":
29+
sys.setrecursionlimit(10**7)
30+
t = 1
31+
# t = int(input())
32+
for _ in range(t):
33+
solve()
34+
35+
36+
# @nc code=end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @nc app=nowcoder id=4fbfd49326934c1d850ba4e90bc41129 topic=314 question=10055877 lang=Python3
2+
# 2026-04-27 07:54:37
3+
# https://www.nowcoder.com/practice/4fbfd49326934c1d850ba4e90bc41129?tpId=314&tqId=10055877
4+
# [NP35] 朋友的年龄是否相等
5+
6+
# @nc code=start
7+
8+
import sys, math
9+
from collections import deque, defaultdict, Counter
10+
import heapq, bisect
11+
input = lambda: sys.stdin.readline().rstrip()
12+
13+
def solve():
14+
ages = list(map(int,input().strip().split()))
15+
print(True if ages[0] == ages[1] else False)
16+
17+
if __name__ == "__main__":
18+
sys.setrecursionlimit(10**7)
19+
t = 1
20+
# t = int(input())
21+
for _ in range(t):
22+
solve()
23+
24+
25+
# @nc code=end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:57:09
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 07:57:13
6+
'''
7+
# @nc app=nowcoder id=13ca6fc3f6a145a5b6642b26d6575634 topic=314 question=10055878 lang=Python3
8+
# 2026-04-27 07:57:09
9+
# https://www.nowcoder.com/practice/13ca6fc3f6a145a5b6642b26d6575634?tpId=314&tqId=10055878
10+
# [NP36] 谁的数字大
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+
ages = list(map(int,input().strip().split()))
21+
print(True if ages[0] > ages[1] else False)
22+
print(True if ages[0] < ages[1] else False)
23+
24+
if __name__ == "__main__":
25+
sys.setrecursionlimit(10**7)
26+
t = 1
27+
# t = int(input())
28+
for _ in range(t):
29+
solve()
30+
31+
# @nc code=end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 07:58:30
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 08:00:43
6+
'''
7+
# @nc app=nowcoder id=0be51146e30f4fa0ad1a6aac9078c1af topic=314 question=10055884 lang=Python3
8+
# 2026-04-27 07:58:30
9+
# https://www.nowcoder.com/practice/0be51146e30f4fa0ad1a6aac9078c1af?tpId=314&tqId=10055884
10+
# [NP37] 不低于与不超过
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+
k,x,y = map(float,input().split())
21+
22+
print(True if k <= x else False)
23+
print(True if k >= y else False)
24+
25+
if __name__ == "__main__":
26+
sys.setrecursionlimit(10**7)
27+
t = 1
28+
# t = int(input())
29+
for _ in range(t):
30+
solve()
31+
32+
33+
# @nc code=end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-27 08:02:10
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-27 08:03:15
6+
'''
7+
# @nc app=nowcoder id=d1f6b7dd048f48c58d974553f0c5a3bc topic=314 question=10055925 lang=Python3
8+
# 2026-04-27 08:02:10
9+
# https://www.nowcoder.com/practice/d1f6b7dd048f48c58d974553f0c5a3bc?tpId=314&tqId=10055925
10+
# [NP38] 牛牛的逻辑运算
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+
x,y = map(int,input().split())
21+
print(x and y)
22+
print(x or y)
23+
print(not x)
24+
print(not y)
25+
26+
if __name__ == "__main__":
27+
sys.setrecursionlimit(10**7)
28+
t = 1
29+
# t = int(input())
30+
for _ in range(t):
31+
solve()
32+
33+
34+
# @nc code=end

0 commit comments

Comments
 (0)