The first line contains the delimiter . The next lines each contain an integer, which represents the elements of the list/array. You have to read the input to the End-Of-File.
Output Format
Print all the integers from the array that are less than the given upper limit in value on separate lines. The sequence should be the same as it was in the original array.
Constraints
For any element, in the array,
Note
The purpose of this challenge is to learn how to write your own implementation of a filter function. We recommend not using the inbuilt library function.
Given a list, repeat each element in the list amount of times. The input and output portions will be handled automatically by the grader. You need to write a function with the recommended method signature.
Input Format
The first line contains the integer where is the number of times you need to repeat the elements. The next lines each contain an integer. These are the elements in the array.
Output Format
Output each element of the original list times, each on a separate line. You have to return the list/vector/array of integers. The relative positions of the values should be the same as the original list provided in the input.
Constraints
Sample Input
3
1
2
3
4
Sample Output
1
1
1
2
2
2
3
3
3
4
4
4
제출 ]
def f(num:Int,arr:List[Int]):List[Int] ={
return arr.flatMap(e=>List.fill(num)(e))
}
풀이 ]
List클래스의 함수 flatMap을 이용한다. 비슷한 함수로 map이 있는데 둘간의 차이를 보면