首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【7-9 有重复的数据I (20 分)】【此题卡输入,需要自己写个输入挂】

【7-9 有重复的数据I (20 分)】【此题卡输入,需要自己写个输入挂】

作者头像
_DIY
发布2019-09-30 16:28:44
4630
发布2019-09-30 16:28:44
举报

参考一个博客的输入挂,先挂在此处,以备以后使用。

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());
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档