zoukankan      html  css  js  c++  java
  • 找水王

    设计了一个灌水论坛。信息学院的学生都喜欢在上面交流灌水,传说在论坛上有一个“水王”,他不但喜欢发帖,还会回复其他ID发的每个帖子。坊间风闻该“水王”发帖数目超过了帖子数目的一半。 如果你有一张当前论坛的帖子(包括回帖)列表,其中帖子的作者的ID也在其中,你能快速的找到这个传说中的水王吗?

    水王主要是帖子数超过了半数

     

    package dao;

     

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.ResultSet;

    import java.sql.Statement;

    import java.util.ArrayList;

     

    import com.sun.org.apache.regexp.internal.recompile;

    public class Dao

    {

        String findRyan()

        {

     

            String db_url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8";

            String db_user = "root";

            String db_password = "";

            Connection conn = null;

            Statement state = null;

            ResultSet rs = null;

            ArrayList<String> list = new ArrayList<>();

            try

            {

                Class.forName("com.mysql.jdbc.Driver");

                conn = DriverManager.getConnection(db_url, db_user, db_password);

                state = conn.createStatement();

                rs = state.executeQuery("select uid,reid from post");

                while (rs.next())

                {

                    String idList = rs.getString("uid") + "|" + rs.getString("reid");

                    if (!(idList).equals(""))

                    {

                        for (String id : idList.split("\|"))

                        {

                            list.add(id);

                        }

                    }

                }

                ;

            } catch (Exception e)

            {

                e.printStackTrace();

            }

            System.out.println(list);

            for (int i = 0; i < list.size() - 1; i++)

            {

                if (!list.get(i).equals(list.get(i + 1)))

                {

                    list.set(i, "a");

                    list.set(i + 1, "a");

                    i=i+1;

                }

            }

            System.out.println(list);

            return null;

        }

     

        public static void main(String[] args)

        {

            Dao aDao = new Dao();

            aDao.findRyan();

        }

    }

  • 相关阅读:
    线段树
    哈希,hash
    单调栈
    树的重心
    背包问题
    最小生成树
    二分图匹配
    题解 P6355 [COCI2007-2008#3] DEJAVU
    题解 P6745 『MdOI R3』Number
    题解 P2080 增进感情
  • 原文地址:https://www.cnblogs.com/zhjvvvvvv/p/13088671.html
Copyright © 2011-2022 走看看