2024-09-21 02:58:38 发布
网友
这是一个c++代码,如何在python中实现?你知道吗
while(scanf("%lld",&n)!=EOF) { cout<<convert(n)<<endl; }
在Python中,通常不使用scanf和friends,而是将一行或整个文件读入一个字符串,然后使用字符串操作来获得所需的结果。你知道吗
scanf
在您的示例中,您可以执行以下操作:
import sys for line in sys.stdin: for word in line.split(): number = int(word) ... = convert(number)
可以使用try-except
可以使用下面的链接
https://stackoverflow.com/a/38621838/4557946
这大致相当于:
def convert(input): #do something with your input import sys for line in sys.stdin: convert(int(line))
在Python中,通常不使用
scanf
和friends,而是将一行或整个文件读入一个字符串,然后使用字符串操作来获得所需的结果。你知道吗在您的示例中,您可以执行以下操作:
可以使用try-except
可以使用下面的链接
https://stackoverflow.com/a/38621838/4557946
这大致相当于:
相关问题 更多 >
编程相关推荐