Huawei Machine Test-delete consecutive occurrences of a number greater than or equal to 3

Source: Internet
Author: User

Enter a set of numbers (up to 15), remove the number of consecutive times greater than or equal to three, if removed and still have a continuous number of times greater than or equal to three, continue to do the same process until the result does not appear consecutive times greater than or equal to three of the number so far.
If the final elimination is complete, output "none"


Input: 1 1 1 1 2 2 2 1 3 3 3 3 1 1 1

Output: None


#include <iostream> #include <vector>using namespace Std;int kk=1;void delete_num (vector<int> a) {int Len = A.size (); int i,j;int flag=0;for (i=0;i<len;i++) {int k=i;for (j=k+1;j<len;) {if (A[k]==a[j]) j++;else{if (j-k >=3) {a.erase (A.begin () +k,a.begin () +j); flag=1;break;} else{k=j;j=k+1;}}} if (flag) break;if (j-k>=3) {a.erase (A.begin () +k,a.begin () +j); break;}} cout<< "<<kk<<": "For (I=0;i<a.size (); i++) cout<<a[i]<<" ";cout<<endl; if (A.size () ==len) {cout<< "final result:"; for (I=0;i<a.size (); i++) cout<<a[i]<< "";} Else{if (A.size ()!=0) {kk++;d elete_num (a);} elsecout<< "Final result: None" <<endl;}} void Main () {int n;vector<int> a;cin>>n;while (GetChar ()! = ' \ n ') {a.push_back (n); cin>>n;} A.push_back (n);d Elete_num (a); Cout<<endl;}

Test results:


Huawei Machine Test-delete consecutive occurrences of numbers greater than or equal to 3

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.