[英]why to put space between %d and %c while inputting there values using scanf
[英]Inputting Multiple values through Scanf - C
我正在嘗試解決SPOJ問題。 我被困在這里。
對於輸入,它要求我以下內容作為輸入
下一行包含n個元素,ai(1 <= i <= n)用空格隔開。
我可以使用循環並通過scanf輸入用戶分別給定的每個元素。 但是根據問題標准,我假設我們需要在一行中一次通過scanf接受輸入。 就像scanf(“%d%d%d”,&a1&a2等)。
但是范圍超過10 ^ 6,我不確定如何通過scanf在一行中動態輸入多個值。
您可以按照您的說法運行迭代,因為scanf
不在乎哪種空格分隔整數輸入。
因此: for (i = 0; i < n; ++i) scanf("%d", &array[i]);
適用於以下類型的輸入:
3 2 1 2 3 8
以及類型
3
2
1
2
3
8
不管您是否在一行中輸入數字,這都將有效,因為scanf會忽略空格
int arr[1000001]; // Take an array to store the inputs
for(i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.