Compile Error
foo.cc: In function 'int main()': foo.cc:30:40: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)' 30 | auto doesExistInList = find(list.begin(), list.end(), a[i]); | ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/bits/locale_facets.h:48, from /usr/include/c++/13/bits/basic_ios.h:37, from /usr/include/c++/13/ios:46, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from foo.cc:1: /usr/include/c++/13/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)' 435 | find(istreambuf_iterator<_CharT> __first, | ^~~~ /usr/include/c++/13/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed: foo.cc:30:40: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>' 30 | auto doesExistInList = find(list.begin(), list.end(), a[i]); | ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
bool isPermutation = true;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> list;
for (int i = 0; i < n; ++i) {
if (a[i] > n || a[i] < 1) {
cout << "NO" << endl;
isPermutation = false;
}
auto doesExistInList = find(list.begin(), list.end(), a[i]);
if (doesExistInList != list.end()) {
cout << "NO" << endl;
isPermutation = false;
} else {
list.push_back(a[i]);
}
}
if (isPermutation) {
cout << "YES" << endl;
}
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1055 Array Permutation
- Contest
- Brain Booster #3
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-05-06 15:21:08
- Judged At
- 2024-11-11 03:34:37
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes