C++ Bc. 46 cpp

Z GeoWikiCZ
Skočit na navigaci Skočit na vyhledávání
#include <iostream>
#include <matvec/matvec.h>

using namespace GNU_gama;

Mat<int> hlazeni(const Mat<int>& M)
{
  Mat<int> N(M.rows(), M.cols());

  for (unsigned r=1; r<=M.rows(); r++)
    for  (unsigned s=1; s<=M.cols(); s++)
      {
	unsigned p, q;
	unsigned m=0;
	unsigned n=0;
	for (int i=-1; i<=1; i++)
	  {
	    p = r + i;
	    if (p == 0) continue;
	    if (p > M.rows()) continue;

	    for (int j=-1; j<=1; j++)
	      {
		q = s + j;
		if (q == 0) continue;
		if (q > M.cols()) continue;
		if (p == r && q == s) continue;

		m += M(p,q);
		n++; 
	      }
	  }
	
	m += n*M(r,s); 
	n *= 2;

	N(r,s) = (double(m)/n + 0.5);
      }

  return N;
}

int main()
{
  Mat<int> A(4,5);
  A = 11, 12, 13, 14, 15,     //     15 15 16 17 18
      21, 22, 23, 24, 25,     // ==> 21 22 23 24 25
      31, 32, 33, 34, 35,     //     31 32 33 34 35
      41, 42, 43, 44, 45;     //     38 39 40 41 41

  std::cout << A << "\n" << hlazeni(A);
}

[ Zpět ]