Find water Wang

Wang Posts known water more than half, according to this condition, application method to find water to offset the king, and the remaining water is the last king

Source:

import java.util.Scanner;

public class shui {
    public static void main(String[] args) {
        Scanner sca=new Scanner(System.in);
        System.out.println("输入帖子总数:");
        int count=sca.nextInt();
        int a[]=new int[count];
        System.out.println("输入帖子ID:");
        for(int i=0;i<count;i++)
        {
            a[i]=sca.nextInt();
        }
       max (A);
    } 
                     {Public   static  void max ( int A []) { // find water Wang 
        int C =. 1; // J is an ID number that appears 
        int max; // assumed to max (water king ID) number appears 
        max = A [0]; // assumed that the first number is water king ID 
        for ( int I =. 1; I <a.length; I ++ ) 
        { 
            IF (! max = A [I]) 
            { 
                C = C-. 1 ;
                 IF (C <= 0)     // if j <= 0, it indicates that the water is not king max ID. Because more than half the water Posts Wang, no matter how offset will not be less than or equal 0 

                    max = A [I +. 1];     // all want to change other water ID king ID 
                    C =. 1;         // redefine the number of occurrences of water ID Wang 
                    I ++ ; 
                } 
            } 
            the else 
            { 
                max = A [I]; 
                C = C +1; // count the number of water king posts 
            } 
        } 
        System.out.println ( "King water ID is" + max); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/sengzhao666/p/10951078.html