酷代码 AI
菜单

错误信息 Traceback (most recent call last): File "Main.py", line 19, in <module> main() File "Main.py", line 11, in main N = int(input().strip()) ValueError: invalid literal for int() with base 10: '13 a b c' /1209/4.in: non-zero return = 1 Traceback (most recent call last): File "Main.py", line 19, in <module> main() File "Main.py", line 11, in main N = int(input().strip()) ValueError: invalid literal for int() with base 10: '13 a b c' /1209/5.in: non-zero return

输入格式包含多个参数,需要读取整行并分割。 修改代码以正确解析输入。 ```python def hanoi(n, source, target, auxiliary, moves): if n == 1: moves.append(f"{source}->{n}->{target}") else: hanoi(n - 1, source, auxiliary, target, moves) moves.append(f"{source}->{n}->{target}") hanoi(n - 1, auxiliary, target, source, moves) def main(): data = input().strip().split() N = int(data[0]) moves = [] hanoi(N, 'a', 'c', 'b', moves) print(2 N - 1) for move in moves: print(move) if __name__ == "__main__": main() ``` [2026-01-06 12:34:41 | AI问答 | 182点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多