Classroom Exercises-Find buckets (4.24)

Source: Internet
Author: User

Topic:

A three-person line designed a forum for irrigation. With the development of the Forum, the administrator found that the water king did not, but the statistical results show that there are three posts a lot of ID. According to the statistics of their posts more than 1/4, you can quickly find them from the list of posts?

First, design ideas

The teacher has been stressed in class with the last water king method similar, although the class did not come up with a method, but the class through thinking and observation to find water King's program, only on the original basis from a elimination of two, into a elimination of four; three buckets can be said to be equivalent, the number is more than One-fourth, Therefore, after the elimination of four at a time, the rest must be three buckets. Need to change from a water king to save three buckets, the change method is similar to the previous program. So just copy and paste the last program, and then modify it a little bit.

Second, the source code

1#include <iostream.h>2 intMain ()3 {4     inti,j,k=1, q=1, p=1, Shuitong1,shuitong2,shuitong3;5     inta[ -];6cout<<"Please enter the number of IDs:";7Cin>>J;8cout<<"Please enter ID:";9      for(i=0; i<j;i++)Ten     { OneCin>>A[i]; A     } -shuitong1=a[0]; -shuitong2=a[1]; theshuitong3=a[2]; -      for(i=3; i<j;i++) -     { -         if(shuitong1!=a[i]&&shuitong2!=a[i]&&shuitong3!=A[i]) +         { -k=k-1; +q=q-1; Ap=p-1; at             if(k<=0&&q>0&&p>0) -             { -shuitong1=a[i+1]; -k=1; -i++; -             } in             Else if(k>0&&q<=0&&p>0) -             { toshuitong2=a[i+1]; +q=1; -i++; the             } *             Else if(k>0&&q>0&&p<=0) $             {Panax Notoginsengshuitong3=a[i+1]; -p=1; thei++; +             } A             Else if(k<=0&&q<=0&&p>0) the             { +shuitong1=a[i+1]; -k=1; $shuitong2=a[i+2]; $q=1; -i=i+2; -             } the             Else if(k<=0&&q>0&&p<=0) -             {Wuyishuitong1=a[i+1]; thek=1; -shuitong3=a[i+2]; Wup=1; -i=i+2; About             } $             Else if(k>0&&q<=0&&p<=0) -             { -shuitong2=a[i+1]; -q=1; Ashuitong3=a[i+2]; +p=1; thei=i+2; -             } $             Else if(k<=0&&q<=0&&p<=0) the             { theshuitong1=a[i+1]; thek=1; theshuitong2=a[i+2]; -q=1; inshuitong3=a[i+3]; thep=1; thei=i+3; About             } the         } the         Else if(shuitong1==a[i]&&shuitong2!=a[i]&&shuitong3!=A[i]) the         { +shuitong1=A[i]; -k=k+1; the         }Bayi         Else if(shuitong1!=a[i]&&shuitong2==a[i]&&shuitong3!=A[i]) the         { theShuitong2=A[i]; -q=q+1; -         } the         Else if(shuitong1!=a[i]&&shuitong2!=a[i]&&shuitong3==A[i]) the         { theshuitong3=A[i]; thep=p+1; -         } the      the     } thecout<<"bucket IDs are:"<<shuitong1<<","<<shuitong2<<","<<shuitong3<<Endl;94     return 0; the}

Iii. Results

Iv. Summary of the experiment

The most I've learned in this experiment is to learn the analogy, and when I master a method, learn to use it to solve a series of similar problems. First of all, to find the same two questions, see if we can do similar treatment, after analysis, if you can, and then find their differences, to make corresponding changes to the differences, the problem should be able to solve.

Classroom Exercises-Find buckets (4.24)

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.