'commit'
This commit is contained in:
36
TangDou/CSP-J/J2-2021/4_Vector.cpp
Normal file
36
TangDou/CSP-J/J2-2021/4_Vector.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 200010;
|
||||
int n, cnt;
|
||||
|
||||
struct Node {
|
||||
int id, value;
|
||||
};
|
||||
vector<Node> a;
|
||||
//70分,不能AC
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
a.push_back({i, x});
|
||||
}
|
||||
|
||||
while (cnt < n) {
|
||||
int flag = 2;
|
||||
//枚举vector中每个数字,之所以采用迭代器,是因为循环过程中要删除
|
||||
for (auto it = a.begin(); it != a.end();) {
|
||||
Node x = *it;
|
||||
if (x.value != flag) {
|
||||
flag = x.value;
|
||||
printf("%d ", x.id);
|
||||
cnt++;
|
||||
a.erase(it);
|
||||
} else
|
||||
++it;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user