import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
public static List<Integer> rotLeft(List<Integer> a, int d) {
int rest = d % a.size();
List<Integer> first = a.subList(rest, a.size());
List<Integer> last = a.subList(0, rest);
List<Integer> joined = new ArrayList<>();
joined.addAll(first);
joined.addAll(last);
return joined;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
int n = Integer.parseInt(firstMultipleInput[0]);
int d = Integer.parseInt(firstMultipleInput[1]);
List<Integer> a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());
List<Integer> result = Result.rotLeft(a, d);
bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(joining(" "))
+ "\n"
);
bufferedReader.close();
bufferedWriter.close();
}
}
같은 문제 파이썬 풀이 추가)
#!/bin/python3
import math
import os
import random
import re
import sys
def rotateLeft(d, arr):
front = arr[:d]
back = arr[d:]
return back + front
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
d = int(first_multiple_input[1])
arr = list(map(int, input().rstrip().split()))
result = rotateLeft(d, arr)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()
'algorithm > java' 카테고리의 다른 글
null pointer exception 예방하기 (0) | 2021.07.11 |
---|---|
java int와 Integer의 차이 (0) | 2021.07.04 |
hackerrank/warm up/Repeated String (0) | 2021.06.20 |
hackerranck/warm up/jumping on the clouds (0) | 2021.06.13 |
java 개발이 처음일 때 볼 수 있는 에러 (0) | 2021.06.02 |