我可以在Python:蟒蛇:讀取流一步整數的一步
n = int(input())
a = [int(x) for x in input().split()]
我可以在C++:
int main()
{
int n, x;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
somthing(x)
}
}
如何寫在Python的(3.X)?我可以處理流程中的數字而不用全部保存在列表中嗎? (例如)
輸入數據:
6
1 4 4 4 1 1
我可以使用sys.stdin?
UPD:
好吧,我寫了這個:
import sys
n = int(input())
i = 0
c = ""
s = ""
while i < n:
c = sys.stdin.read(1)
if c in [" ","\n"]:
x = int(s)
somthing(x)
s = ""
i += 1
else:
s += c
是否有一個更優雅的解決方案?
你看過我的回答嗎?我編輯過它。 – JRodDynamite
是的。你的回答是錯誤的 – user2704006
輸入數據格式不清楚。是面向行的還是不行? – VPfB