Created
April 15, 2017 02:46
-
-
Save chiangqiqi/08253feaa13d2b7bde2e79ba8aa75fd6 to your computer and use it in GitHub Desktop.
simpe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
using std::vector; | |
void process(const vector<int>& vec1, vector<int>& vec2) { | |
unsigned int i = 0; | |
while(i < vec1.size()) { | |
if (vec1[i] == 1 && vec1[i+1] == 2) { | |
// do not copy and skip the other 2 | |
i += 4; | |
} else { | |
vec2.push_back(vec1[i]); | |
i += 1; | |
} | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
vector<int> v = {7 , 1, 2, 5, 16, 8}; | |
// 遍历向量并打印其中的值 | |
vector<int> v2 = {}; | |
process(v, v2); | |
for(int n : v2) { | |
std::cout << n << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment