Replace Number at Index


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

請設計一個程式,讓使用者輸入 5 個整數,接著輸入一個索引值 (0~4),以及一個新的數字,將對應索引位置的數字替換為新數字,並輸出修改後的陣列。

若索引值超出範圍 (小於 0 或大於 4),則輸出 "Index is out of range!" 並結束程式。

輸入

第一行:輸入 5 個整數,表示陣列的初始值。 第二行:輸入一個索引值 (0~4) 和一個新數字。

輸出

若索引值在範圍內,則輸出修改後的陣列 (數字之間以空格分隔)。 若索引值超出範圍,則輸出 "Index is out of range!"。

範例輸入 #1

10 20 30 40 50
2 99

範例輸出 #1

10 20 99 40 50

說明:將索引 2 的數字 30 替換為 99,最終輸出 10 20 99 40 50。

範例輸入 #2

3 6 9 12 15
-1 0

範例輸出 #2

Index is out of range!

Comments

There are no comments at the moment.