/code_2694580.cpp: In function ‘int main()’:
/code_2694580.cpp:12:105: error: no matching function for call to ‘find(std::vector::iterator, std::vector::iterator, __gnu_cxx::__alloc_traits<std::allocator >::value_type)’
vector::iterator findit = find(myvec.begin(), myvec.end(), (myvec[myvec.size() - 1] * z + i) % m);
^
/code_2694580.cpp:12:105: note: candidate is:
In file included from /usr/include/c++/4.9/bits/locale_facets.h:48:0,
from /usr/include/c++/4.9/bits/basic_ios.h:37,
from /usr/include/c++/4.9/ios:44,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from /code_2694580.cpp:1:
/usr/include/c++/4.9/bits/streambuf_iterator.h:369:5: note: template typename __gnu_cxx::__enable_if<std::__is_char::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)
是這裡的編譯器不支援vector嗎?
在自己電腦編譯可過
求解
程式碼:
#include <iostream>
#include <vector>
using namespace std;
int main() {
int z, i, m, l, count = 1;
while (cin >> z >> i >> m >> l, z || i || m || l) {
vector<int>myvec;
myvec.push_back(l);
cout << "Case " << count << ": ";
while (1) {
vector<int>::iterator findit = find(myvec.begin(), myvec.end(), (myvec[myvec.size() - 1] * z + i) % m);
if (findit != myvec.end()) {
cout << myvec.end() - findit << endl;
break;
}
else myvec.push_back((myvec[myvec.size() - 1] * z + i) % m);
}
count++;
}
}