'commit'
This commit is contained in:
28
TangDou/CSP-J/AcWingTraining/T1/4089_BruteForce.cpp
Normal file
28
TangDou/CSP-J/AcWingTraining/T1/4089_BruteForce.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 200010;
|
||||
int n, a[N];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
|
||||
int cnt = 0;
|
||||
while (cnt < n) { // 入果篮个数
|
||||
int t = -1; // 前一个是什么水果,0或1
|
||||
for (int j = 1; j <= n; j++) { // 遍历每一个水果
|
||||
// 如果与前一个不同,并且没有被选出
|
||||
if (a[j] != t && a[j] != -1) {
|
||||
cout << j << " "; // 被选出
|
||||
cnt++; // 多一个被选出
|
||||
// 重新定义前一个,为后面的循环做准备
|
||||
t = a[j]; // 继续向后
|
||||
a[j] = -1; // 标记已被选出
|
||||
}
|
||||
}
|
||||
// 每一轮结束输出换行
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user