Algorithm
백준 1940번: 주몽
qlyh8
2018. 9. 23. 15:43
문제출처: https://www.acmicpc.net/problem/1940
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); int M = Integer.parseInt(reader.readLine()); int count = 0; ArrayList<String> list = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); for(int i=0 ; i<N ; i++) list.add(tokenizer.nextToken()); while(list.size() > 1){ int value1 = Integer.parseInt(list.get(0)); int value2 = M - value1; if(list.contains(String.valueOf(value2)) && value1!=value2){ count++; list.remove(String.valueOf(value2)); } list.remove(0); } System.out.println(count); } } | cs |