解题代码
#include<iostream>
#include<set>
#include<functional>
using namespace std;
int main()
{
int n, temp, cnt = 1, ret = 0;
multiset<int,greater<int> > s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
s.insert(temp);
}
for (auto x : s)
if (x <= cnt++) break;
else ret++;
printf("%d", ret);
return 0;
}
测试结果
问题整理
1.for循环中的break语句的判断条件中如果存在自加自减数,建议不要继续使用该数作为值传递或是输入输出,因为题目通常会给出不同的case使这条break语句成立或不成立,那自加自减数会存在1的差值。