public class Main {
static int checkArr[];
static int myArr[];
static int checkSecret;
public static void main(String[] args) throws NumberFormatException, IOException {
// ISC - L1
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int S = Integer.parseInt(st.nextToken());
int P = Integer.parseInt(st.nextToken());
// pRe
int marker = 0;
char A[] = new char[S]; // sliding window
checkArr = new int[4];
myArr = new int[4]; // sliding window > 각 값을 A C G T 공간에 stack하여 checkArr과 비교할 준비
checkSecret = 0;
static + type + label 사용
// External Module(1/2) - endpoint in
private static void Add(char c) {
switch(c) {
case 'A' :
myArr[0]++;
if (myArr[0] == checkArr[0])
checkSecret++;
break;
case 'C' :
myArr[1]++;
if (myArr[1] == checkArr[1])
checkSecret++;
break;
case 'G' :
myArr[2]++;
if (myArr[2] == checkArr[2])
checkSecret++;
break;
case 'T' :
myArr[3]++;
if (myArr[3] == checkArr[3])
checkSecret++;
break;
}
}
// External Module(2/2) - startpoint out
private static void Remove(char c) {
switch (c) {
case 'A' :
if (myArr[0] == checkArr[0])
checkSecret--;
myArr[0]--;
break;
case 'C' :
if (myArr[1] == checkArr[1])
checkSecret--;
myArr[1]--;
break;
case 'G' :
if (myArr[2] == checkArr[2])
checkSecret--;
myArr[2]--;
break;
case 'T' :
if (myArr[3] == checkArr[3])
checkSecret--;
myArr[3]--;
break;
}
}
private static void Function() {} 사용
class와 인자의 사용
static class Node {
public int value;
public int index;
Node(int value, int index) {
this.value = value;
this.index = index;
}
}
// ISC - L2
Deque<Node> mydeque = new LinkedList<>();
st = new StringTokenizer(br.readLine());
for (int i = 0; i < W; i ++) {
int now = Integer.parseInt(st.nextToken());
while (!mydeque.isEmpty() && mydeque.getLast().value > now) {
mydeque.removeLast();
}
mydeque.addLast(new Node(i, now));
if (mydeque.getFirst().index <= i - W) // 덱에서 인덱스 참조해서 윈도우 크기에서 벗어나면 제거
mydeque.removeFirst();
// 최솟값 프린트
bw.write(mydeque.getFirst().value+ " ");
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
// ISC - L1
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
// ISC - L2
mData[] A = new mData[N];
for (int i = 0; i < N; i++) {
A[i] = new mData(i, Integer.parseInt(br.readLine()));
}
Arrays.sort(A);
// Distance
int max = 0;
for (int i = 0; i < N; i++) {
if (max < A[i].index - i)
max = A[i].index - i;
}
// OEC
System.out.println(max+1);
}
}
class mData implements Comparable<mData> {
int value;
int index;
public mData(int index, int value) {
super();
this.index = index;
this.value = value;
}
@Override
public int compareTo(mData o) {
return this.value - o.value;
}
}
'코테 기초' 카테고리의 다른 글
Deque 사용 (0) | 2022.12.05 |
---|---|
switch > case 형식 (0) | 2022.12.05 |
SLIDING WINDOW (0) | 2022.12.05 |
field : 배열을 만들 필요 없는 경우 (0) | 2022.12.05 |
Two Pointers (0) | 2022.12.05 |