|
|
|
|
|
|
|
|
|
|
|
|
for(int k = 0; k < j; ++k)
return false;
as soon the first duplicate is found.
#include <iostream> #include <vector> #include <set> bool verify_row( const std::vector<int>& row ) { std::set<int> unique ; for( int v : row ) if( v != 0 && unique.insert(v).second == false ) return false ; // duplicate non-zero value in row return true ; } bool verify_col( const std::vector< std::vector<int> >& matrix, std::size_t col_no ) { std::set<int> unique ; for( const auto& row : matrix ) if( col_no < row.size() && row[col_no] != 0 && unique.insert( row[col_no] ).second == false ) return false ; return true ; |
You don't need another container for colums (if the first dimension is column): |
It is C++11. Should work with a current version of Dev C++. For instance, Orwel Dev C++ http://sourceforge.net/projects/orwelldevcpp/files/Setup%20Releases/Dev-Cpp%205.11%20TDM-GCC%204.9.2%20Setup.exe/download To enable C++11: http://www.cplusplus.com/doc/tutorial/introduction/devcpp/ |