Source:
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(); } }
Ideas:
Since more than half the number of post Zhan water, so water is king id number and other offset, the last remaining water king's id, the first a second if the same comparison, the num ++, if not the same after the two continue comparing a, it is determined points.