Skip to content

Commit fcdb822

Browse files
authored
Create 백준-1253-좋다.java
1 parent 85653de commit fcdb822

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main{
6+
7+
public static void main(String[] args) throws IOException{
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
12+
int N = Integer.parseInt(br.readLine());
13+
int answer = 0;
14+
long[] arr = new long[N];
15+
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
18+
for(int i = 0; i<N; i++){
19+
arr[i] = Integer.parseInt(st.nextToken());
20+
}
21+
22+
Arrays.sort(arr);
23+
24+
for(int k = 0; k<N; k++){
25+
26+
long find = arr[k];
27+
int start = 0;
28+
int end = N-1;
29+
30+
while(start < end){
31+
32+
if (arr[start] + arr[end] == find){
33+
34+
if(start != k && end != k){
35+
answer++;
36+
break;
37+
}else if( start == k){
38+
start++;
39+
}else if( end == k){
40+
end--;
41+
}
42+
} else if(arr[start] + arr[end] > find){
43+
end--;
44+
}else if (arr[start] + arr[end] < find){
45+
start++;
46+
}
47+
}
48+
}
49+
50+
bw.write(answer+"");
51+
bw.flush();
52+
}
53+
54+
}

0 commit comments

Comments
 (0)