package 신규아이디추천;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main {
static int N;
static int K;
public static void delete(ArrayList<Integer> list)
{
ArrayList<Integer> result = new ArrayList<>();
int index=0;
while(!list.isEmpty())
{
index=index+K-1;
while(index>=list.size())
index = index-list.size();
result.add(list.remove(index));
}
System.out.println(result.toString().replace('[','<').replace(']','>'));
}
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
N = Integer.parseInt(tokenizer.nextToken());
K = Integer.parseInt(tokenizer.nextToken());
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < N; ++i)
list.add(i+1);
delete(list);
}
}
이렇게 풀어서 통과 했는데
다른 분께서 푼걸보니
while(!list.isEmpty())
{
index=index+K-1;
while(index>=list.size())
index = index-list.size();
result.add(list.remove(index));
}
[내 코드]
while (list.size() > 0)
{
index = (index + K - 1) % list.size();
result.add(list.remove(index));
}
요렇게 간단히 풀었드라....