参考的输入挂,先挂在此处,以备以后使用。
import java.io.*;import java.util.*;import java.math.*; public class Main{ public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); out.close(); }}class InputReader{ BufferedReader buf; StringTokenizer tok; InputReader() { buf = new BufferedReader(new InputStreamReader(System.in)); } boolean hasNext() { while(tok == null || !tok.hasMoreElements()) { try { tok = new StringTokenizer(buf.readLine()); } catch(Exception e) { return false; } } return true; } String next() { if(hasNext()) return tok.nextToken(); return null; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); }}
正确代码:
import java.io.*;import java.util.*;import java.math.*;public class Main{ public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); final int maxn = 100000+10; int[] vis = new int[maxn]; int n = in.nextInt(), num, flag = 0; for(int i = 0; i < n; i++) { num = in.nextInt(); if(vis[num] == 1) flag = 1; vis[num] = 1; } if(flag == 0) out.println("NO"); else out.println("YES"); out.close(); }}class InputReader{ BufferedReader buf; StringTokenizer tok; InputReader(){ buf = new BufferedReader(new InputStreamReader(System.in)); } boolean hasNext() { while(tok == null || !tok.hasMoreElements()) { try { tok = new StringTokenizer(buf.readLine()); } catch(Exception e) { return false; } } return true; } String next() { if(hasNext()) { return tok.nextToken(); } return null; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); }}