三人行设计了一个灌水论坛。信息学院的学生都喜欢在上面交流灌水,传说在论坛上有一个“水王”,他不但喜欢发帖,还会回复其他ID发的每个帖子。坊间风闻该“水王”发帖数目超过了帖子数目的一半。 如果你有一张当前论坛的帖子(包括回帖)列表,其中帖子的作者的ID也在其中,你能快速的找到这个传说中的水王吗?
要求将设计思想、代码实现、实现截图、个人总结以博文的形式发表。
import java.util.*;
public class water {
public static void main(String[] args) {
Scanner sca=new Scanner(System.in);
System.out.println("------FIND WATER KING!!!------");
System.out.println("Please input post numbers:");
int count=sca.nextInt();
int a[]=new int[count];
int i,j=1,sw;
System.out.println("Please input people ID:");
for(i=0;i<count;i++)
{
a[i]=sca.nextInt();
}
sw=a[0];
for(i=1;i<count;i++)
{
if(sw!=a[i])
{
j=j-1;
if(j<=0)
{
sw=a[i+1];
j=1;
i++;
}
}
else
{
sw=a[i];
j=j+1;
}
}
System.out.println("RESULT:THE WATER KIGN IS "+sw);
}
}