I'm writing a small recursive algorithm. Here is the code:
#include
#include
#include
using namespace std;
vector coins;
int checkchange(int left) {
vector choices (coins.size());
if (left == 0)
return 0;
else {
int min;
for (int i=0;i choices.at(i) = (1 + checkchange(left - coins.at(i)));
}
return min_element(choices.front(),choices.back());
}
}
int main() {
int N;
cin >> N;
for (int i=0;i int c,m,temp,change;
cin >> c >> m;
for (int j=0;j cin >> temp;
coins.push_back(temp);
}
for (int j=0;j cin >> temp;
change = checkchange(temp);
cout << change;
}
}
return 0;
}
I get the following error:
In file included from
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/algorithm:62,
from burningcoins.cpp:3: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:
In function ‘_FIter std::min_element(_FIter, _FIter) [with _FIter =
int]’: burningcoins.cpp:19: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998:
error: invalid type argument of ‘unary *’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998:
error: invalid type argument of ‘unary *’
I've tried compiling with both g++ and gcc, both give me the same error. What am I doing wrong?
Edit:
New Code:
int checkchange(int left) {
vector choices (coins.size());
if (left == 0)
return 0;
else {
for (int i=0;i choices[i] = (1 + checkchange(left - coins.at(i)));
}
return *min_element(choices.begin(), choices.end());
}
}
New error message:
/tmp/ccV3VLsK.o: In function
main':
std::cin'
burningcoins.cpp:(.text+0x16a): undefined reference to
burningcoins.cpp:(.text+0x16f): undefined reference tostd::basic_istream
std::cin'>::operator>>(int&)'
burningcoins.cpp:(.text+0x187): undefined reference to
burningcoins.cpp:(.text+0x18c): undefined reference tostd::basic_istream
std::basic_istream >::operator>>(int&)'>::operator>>(int&)'
burningcoins.cpp:(.text+0x19b): undefined reference to
burningcoins.cpp:(.text+0x1b0): undefined reference tostd::cin'
std::basic_istream >::operator>>(int&)'
burningcoins.cpp:(.text+0x1b5): undefined reference to
burningcoins.cpp:(.text+0x1ec): undefined reference tostd::cin'
std::basic_istream >::operator>>(int&)'
burningcoins.cpp:(.text+0x1f1): undefined reference to
burningcoins.cpp:(.text+0x208): undefined reference tostd::cout'
std::basic_ostream >::operator<<(int)'
burningcoins.cpp:(.text+0x20d): undefined reference to
/tmp/ccV3VLsK.o: In function__static_initialization_and_destruction_0(int, int)':
std::ios_base::Init::Init()'
burningcoins.cpp:(.text+0x261): undefined reference to
burningcoins.cpp:(.text+0x266): undefined reference tostd::ios_base::Init::~Init()'
std::vector >::_M_range_check(unsigned long) const':
/tmp/ccV3VLsK.o: In function
burningcoins.cpp:(.text._ZNKSt6vectorIiSaIiEE14_M_range_checkEm[std::vector >::_M_range_check(unsigned long) const]+0x2d): undefined reference tostd::__throw_out_of_range(char const*)'
std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)':
/tmp/ccV3VLsK.o: In function
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)]+0x259): undefined reference to__cxa_begin_catch'
__cxa_rethrow'
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector>::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)]+0x2be): undefined reference to
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)]+0x2c8): undefined reference to__cxa_end_catch'
std::vector >::_M_check_len(unsigned long, char const*) const':
/tmp/ccV3VLsK.o: In function
burningcoins.cpp:(.text._ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc[std::vector >::_M_check_len(unsigned long, char const*) const]+0x4c): undefined reference tostd::__throw_length_error(char const*)'
__gnu_cxx::new_allocator::deallocate(int*, unsigned long)':
/tmp/ccV3VLsK.o: In function
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim[__gnu_cxx::new_allocator::deallocate(int*, unsigned long)]+0x1c): undefined reference tooperator delete(void*)'
__gnu_cxx::new_allocator::allocate(unsigned long, void const*)':
/tmp/ccV3VLsK.o: In function
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[__gnu_cxx::new_allocator::allocate(unsigned long, void const*)]+0x35): undefined reference tostd::__throw_bad_alloc()'
operator new(unsigned long)'
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[__gnu_cxx::new_allocator::allocate(unsigned long, void const*)]+0x45): undefined reference to
/tmp/ccV3VLsK.o:(.eh_frame+0x12): undefined reference to__gxx_personality_v0'
__gxx_personality_v0'
/tmp/ccV3VLsK.o:(.eh_frame+0x4f): undefined reference to
collect2: ld returned 1 exit status
No comments:
Post a Comment