Advertisement
sellmmaahh

prva-parc-2012-zad3-Stacionarni Element

Aug 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdexcept>
  4. #include <cmath>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. template<typename Tip>
  11. bool Stacionarni (const vector<vector<Tip>> &mat) {
  12.     for (int i=0; i<mat.size(); i++)
  13.     {
  14.         if (mat[0].size()!=mat[i].size())
  15.             throw "Parametar nema oblik matrice.";
  16.     }
  17.  
  18.     for (int i=1; i<mat.size()-1; i++) {
  19.         for (int j=1; j<mat[i].size()-1; j++)
  20.         {
  21.             if (mat[i][j]==mat[i][j-1] && mat[i][j]==mat[i][j+1] && mat[i][j]==mat[i-1][j] && mat[i][j]==mat[i+1][j])
  22.                 return true;
  23.         }
  24.     }
  25.     return false;
  26. }
  27. int main () {
  28.     vector<vector<int>> m{{1,2,3,4,5},{1,3,3,3,4},{2,5,3,6,7},{4,78,65,43,2},{12,13,14,15,16}};
  29.     for (int i=0; i<5; i++) {
  30.         for (int j=0; j<5; j++)
  31.             cout<<m[i][j]<<" ";
  32.         cout<<endl;
  33.     }
  34.     try {
  35.         bool JeLiStac{Stacionarni(m)};
  36.         if (JeLiStac) cout<<"Ima stacionarnih elemenata.";
  37.         else cout<<"Nema stacionarnih elemenata.";
  38.     }
  39.     catch(const char x[]){
  40.     cout<<x; }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement