我可以用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
有更优雅的解决方案吗?