Looking for the water king

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.