첫 줄에 N, 다음에 N개의 명제가 주어진다. 명제의 숫자는 정확하게 i개의 명제가 참이다 라는 뜻이다.
총 몇 개의 내용이 참인지 구해보자.
key == value인 경우를 찾기 (명제가 참인 경우)#include <iostream>
#include <map>
using namespace std;
int N;
map<int, int> m;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
int input;
cin >> input;
m[input]++;
}
for (auto iter = m.rbegin(); iter != m.rend(); iter++) {
if (iter->first == iter->second) {
cout << iter->first << endl;
return 0;
}
if (iter->first == 0) {
cout << "-1\\n";
return 0;
}
}
cout << "0\\n";
return 0;
}