[ create a new paste ] login | about

Link: http://codepad.org/0UNxpFc2    [ raw code | output | fork ]

C++, pasted on May 9:
#include <algorithm>
#include <functional>
#include <iterator>
#include <iostream>
#include <locale>

struct Op
{
	template <typename T, size_t Rows>
	bool operator()(const T (&arr)[Rows]) const
	{
		return std::adjacent_find(arr, arr + Rows, std::less_equal<T>()) == arr + Rows;
	}
};

template <typename T, size_t Cols, size_t Rows>
void transform(const T (&m)[Cols][Rows], bool (&arr)[Cols])
{	
	std::transform(m, m + Cols, arr, Op());
}

int main()
{
	const size_t N = 4;
	const size_t M = 4;

	int m[N][M] =
	{
		{1,2,3,4},
		{3,2,1,0},
		{3,4,1,0},
		{3,3,1,0}
	};
	
	bool arr[N];
	transform(m, arr);

	setlocale(LC_ALL, "");
	std::copy(arr, arr+N, std::ostream_iterator<int>(std::cout, " "));

	return 0;
}


Output:
1
0 1 0 0 


Create a new paste based on this one


Comments: