Skip to content

Commit fbb99ff

Browse files
committed
feat: 添加多个新的算法题实现,包括格式化输出和用户输入处理
1 parent 0f1a0d8 commit fbb99ff

11 files changed

Lines changed: 308 additions & 4 deletions
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-23 07:51:35
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:51:42
6+
'''
7+
# @nc app=nowcoder id=ff823846af304a9a8cbbdfe2c9e8874c topic=314 question=10055850 lang=Python3
8+
# 2026-04-23 07:51:35
9+
# https://www.nowcoder.com/practice/ff823846af304a9a8cbbdfe2c9e8874c?tpId=314&tqId=10055850
10+
# [NP10] 牛牛最好的朋友们
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+
name1 = input()
21+
name2 = input()
22+
print(name1 + name2)
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+
32+
# @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-23 07:52:15
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:52:24
6+
'''
7+
# @nc app=nowcoder id=3236759a8bcd43819cfd2b7eb4a9eebb topic=314 question=10055851 lang=Python3
8+
# 2026-04-23 07:52:15
9+
# https://www.nowcoder.com/practice/3236759a8bcd43819cfd2b7eb4a9eebb?tpId=314&tqId=10055851
10+
# [NP11] 单词的长度
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+
word = input()
21+
print(len(word))
22+
23+
if __name__ == "__main__":
24+
sys.setrecursionlimit(10**7)
25+
t = 1
26+
# t = int(input())
27+
for _ in range(t):
28+
solve()
29+
30+
31+
# @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-23 07:53:36
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:53:49
6+
'''
7+
# @nc app=nowcoder id=3bd78a6de34a447fa49571a03f164fd3 topic=314 question=2365106 lang=Python3
8+
# 2026-04-23 07:53:36
9+
# https://www.nowcoder.com/practice/3bd78a6de34a447fa49571a03f164fd3?tpId=314&tqId=2365106
10+
# [NP12] 格式化输出(二)
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+
name = input()
21+
22+
print(name.lower())
23+
print(name.upper())
24+
# print(name.capitalize())
25+
print(name.title())
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-23 07:58:34
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:58:45
6+
'''
7+
# @nc app=nowcoder id=cc6cb2b4aac446da902356fec043f5c1 topic=314 question=2365278 lang=Python3
8+
# 2026-04-23 07:58:34
9+
# https://www.nowcoder.com/practice/cc6cb2b4aac446da902356fec043f5c1?tpId=314&tqId=2365278
10+
# [NP13] 格式化输出(三)
11+
12+
# @nc code=start
13+
14+
import sys, math
15+
from collections import deque, defaultdict, Counter
16+
import heapq, bisect
17+
18+
def solve():
19+
name = input().lstrip().rstrip()
20+
print(name)
21+
22+
if __name__ == "__main__":
23+
sys.setrecursionlimit(10**7)
24+
t = 1
25+
# t = int(input())
26+
for _ in range(t):
27+
solve()
28+
29+
30+
# @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-23 07:59:22
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:59:28
6+
'''
7+
# @nc app=nowcoder id=9baca399143e418cb471159d3b96743e topic=314 question=10055852 lang=Python3
8+
# 2026-04-23 07:59:22
9+
# https://www.nowcoder.com/practice/9baca399143e418cb471159d3b96743e?tpId=314&tqId=10055852
10+
# [NP14] 不用循环语句的重复输出
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+
name = input()
21+
for _ in range(100):
22+
print(name,end='')
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+
32+
# @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-23 08:00:15
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 08:00:22
6+
'''
7+
# @nc app=nowcoder id=0d3cd14ca4bc4e67ace6399a041e961e topic=314 question=10055853 lang=Python3
8+
# 2026-04-23 08:00:15
9+
# https://www.nowcoder.com/practice/0d3cd14ca4bc4e67ace6399a041e961e?tpId=314&tqId=10055853
10+
# [NP15] 截取用户名前10位
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+
name = input()
21+
if len(name) > 10:
22+
name = name[:10]
23+
print(name)
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+
32+
# @nc code=end

niuke/problems/牛客题霸-python入门到实践四十招/NP4.读入整数数字.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@
1010
# [NP4] 读入整数数字
1111

1212
# @nc code=start
13+
import sys, math
14+
from collections import deque, defaultdict, Counter
15+
import heapq, bisect
16+
input = lambda: sys.stdin.readline().rstrip()
1317

18+
def solve():
19+
num = int(input())
20+
print(num)
21+
print(type(num))
22+
23+
if __name__ == "__main__":
24+
sys.setrecursionlimit(10**7)
25+
t = 1
26+
# t = int(input())
27+
for _ in range(t):
28+
solve()
1429

1530

1631
# @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-23 07:44:15
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:45:32
6+
'''
7+
# @nc app=nowcoder id=fe82dc48f4f04b2397a85fb1bdbe34a2 topic=314 question=2365083 lang=Python3
8+
# 2026-04-23 07:44:15
9+
# https://www.nowcoder.com/practice/fe82dc48f4f04b2397a85fb1bdbe34a2?tpId=314&tqId=2365083
10+
# [NP5] 格式化输出(一)
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+
name = input()
21+
print(f"I am {name} and I am studying Python in Nowcoder!")
22+
23+
if __name__ == "__main__":
24+
sys.setrecursionlimit(10**7)
25+
t = 1
26+
# t = int(input())
27+
for _ in range(t):
28+
solve()
29+
30+
31+
# @nc code=end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# @nc app=nowcoder id=0454d1bd28cd499ba06afdabe0fb9caf topic=314 question=10055839 lang=Python3
2+
# 2026-04-23 07:45:56
3+
# https://www.nowcoder.com/practice/0454d1bd28cd499ba06afdabe0fb9caf?tpId=314&tqId=10055839
4+
# [NP6] 牛牛的小数输出
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+
f = float(input())
15+
# print(f"{f:.2f}")
16+
print("{:.2f}".format(f))
17+
18+
if __name__ == "__main__":
19+
sys.setrecursionlimit(10**7)
20+
t = 1
21+
# t = int(input())
22+
for _ in range(t):
23+
solve()
24+
25+
26+
# @nc code=end
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-22 22:02:53
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-23 07:48:25
6+
'''
17
# @nc app=nowcoder id=e302a62c1fbd4bbf84793e8c52ce4705 topic=314 question=10055829 lang=Python3
28
# 2026-04-22 22:02:53
39
# https://www.nowcoder.com/practice/e302a62c1fbd4bbf84793e8c52ce4705?tpId=314&tqId=10055829
410
# [NP7] 小数化整数
511

612
# @nc code=start
713

8-
import sys
14+
import sys, math
15+
from collections import deque, defaultdict, Counter
16+
import heapq, bisect
17+
input = lambda: sys.stdin.readline().rstrip()
918

10-
for line in sys.stdin:
11-
a = line.split()
12-
print(int(a[0]) + int(a[1]))
19+
def solve():
20+
x = float(input())
21+
print(int(x))
22+
23+
if __name__ == "__main__":
24+
sys.setrecursionlimit(10**7)
25+
t = 1
26+
# t = int(input())
27+
for _ in range(t):
28+
solve()
1329

1430

1531
# @nc code=end

0 commit comments

Comments
 (0)