Create an array of integers, where the value of is passed as an argument to the pre-filled function in your editor. This challenge uses a custom checker, so you can create any array of integers. For example, if , you could return , , or any other array of equal length.
Note: Code stubs are provided for almost every language in which you must either fill in a blank (i.e., ____) or write your code in the area specified by comments.
Method Signature
Number Of Parameters: 1
Parameters: [n]
Returns: List or Vector
Input Format
A single integer, .
Constraints
The members returned by the list/vector/array must be integers.
Output Format
The function must return an array, list, or vector of integers. Stub code in the editor prints this to stdout as a space, comma, or semicolon-separated list (depending on your submission language).
Note: Your output need not match the Expected Output exactly; the size of your printed list is confirmed by a custom checker, which determines whether or not you passed each test case.
Sample Input 0
10
Sample Output 0
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Sample Input 1
3
Sample Output 1
[1, 2, 3]
제출 ]
object Solution extends App {
import scala.io.StdIn.readInt
def f(num:Int) : List[Int] = {
return List.fill(num)(1)
Or
return List.range(0,num)
}
println(f(readInt))
}
풀이 ]
num = 4
return List.fill(num)(1) : 리스트 선언시 1로 첫번째인자(num) 만큼 채운다.
ex List(1,1,1,1)
return List.range(0,num) : 리스트 선언시 0~num까지의 수로 채운다.
integers contained in the list, each on a separate line.
Output Format
Output the list with the integers at odd positions removed i.e. the first element, the third element and so on. The relative positions of the remaining even-position elements should be the same as they were in the original array. Each integer will be on a separate line.
NOTE: By odd positions, we mean the first, third, fifth, etc position of the array needs to be filtered out. As per programming language conventions, these might (and they often do) correspond to indices and so on.
Builds a new list by applying a function to all elements of this list.
the element type of the returned list.
the function to apply to each element.
a new list resulting from applying the given function
f
to each element of this list and collecting the results.