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