Facebook
From Colossal Hog, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 245
  1. stack <char> stos;
  2.         char tabo[] = { '(','[','{','<' };
  3.         char tabz[] = { ')',']','}','>' };
  4.         int licznik=0;
  5.         for (int i = 0;i < nap.length();i++)//wrzucenie na stos
  6.         {
  7.                 stos.push(nap[i]);
  8.         }
  9.         for (int i = 0;i < nap.length();i++)
  10.         {
  11.                 for (int j = 0;j < 4;j++)
  12.                 {
  13.                         if (stos.top() == tabo[j]) licznik++;
  14.                         if (stos.top() == tabz[j]) licznik--;
  15.                 }
  16.                 stos.pop();
  17.         }
  18.         if (licznik==0) return true;
  19.         else return false;