First, design ideas
1, I used the method is 22 to calculate the idea of cancellation, adjacent to the two ID in turn.
2. The counter is used to indicate the number of times the water king appears. By default when the counter is 0 o'clock, the water king is the current ID, so the water king appears once, the counter from 0 plus 1, and then compare after an ID, if the same, means that the water king again appears, the counter is added 1; if different, means that the water king does not appear the second, directly offset, the counter is reduced by 1. When the counter is 0, the water king is the current ID, looping in turn.
Second, the Code
//2016/5/18 Letter 1301-1 Huangshan 20133048 looking for the water to stick the King's ID#include <iostream>using namespacestd; #include<string>//a function that is used to find the water king by a 22 offsetvoidKing (stringShui_id[],intamount_id) { stringKing; intI=0; intcounts=0; for(i=0; i<amount_id;i++) { if(counts = =0) {King=Shui_id[i]; Counts=1; } Else { if(King==shui_id[i])//determine if the current ID is the same as the last one{counts++; } Else{counts--; } }} cout<<King; } intMain () {stringid[Ten] = {"Bo feng shui door","I'm the Champ .","double Jackie","6,666,661 Water in the end","6,666,661 Water in the end","Crayon Small New Heart","6,666,661 Water in the end","6,666,661 Water in the end","6,666,661 Water in the end","6,666,661 Water in the end"}; cout<<"ID:"<<Endl; for(intI=0;i<Ten; i++) {cout<<ID[i]<<Endl; } cout<<"The king of Shui is:"<<" "; King (ID,Ten); cout<<Endl; return 0; }
Three
Iv. Summary
This time the search for water King's programming idea is the teacher said 22 offset, but I at his prompt, using is 22 compare then count the thought. The difficulty is that the position of the counter is not set, and finally
Determined by constant grass-manuscript calculus. One of the gains is that it can be achieved without traversing.
Looking for the water king