源代码:

package classfour;

public class test2 {
    static int num=0;
    static String t[]= {"001","002","003","001","001","001","001","002","003","004","001","001","001","002","003"};
    static public void water() {
        for(int i=0;i<t.length;i+=2) {
            if(i<t.length-3) {        
                if((t[0].equals(t[1]))!=true) {
                    if(num>0) {
                        t[0]=t[0];
                        t[1]=t[i+3];
                        num--;
                    }else {
                        t[0]=t[i+2];
                        t[1]=t[i+3];
                    }
                
                }else if((t[0].equals(t[1]))==true) {
                    t[0]=t[0];
                    t[1]=t[i+3];
                    num++;
                    i++;
                }
            }
            
        }
        System.out.println(t[1]);
    }
    public static void main(String[] args) {
        water();
    }
}

思路:

由于水王占发帖数的一半以上,所以将水王id数与其他相抵消,最后剩下水王的id,将第一个与第二个比较如果相同,将num++,如果不相同继续比较后两个,分情况判断。

相关文章:

  • 2022-03-04
  • 2022-12-23
  • 2021-06-12
  • 2022-01-24
  • 2021-12-22
  • 2021-12-02
  • 2021-11-20
猜你喜欢
  • 2021-10-08
  • 2021-10-12
  • 2021-06-11
  • 2022-12-23
  • 2021-10-26
  • 2022-01-24
  • 2021-04-11
相关资源
相似解决方案