Files
python/TangDou/CSP-J/AcWingTraining/T1/4089_BruteForce.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

28 lines
911 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}