Advertisement
kburnik

C++ - Zadatak Esej

Feb 23rd, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. /*
  2.     Zadatak: Esej
  3.    
  4.     Složenost: o(LEN) gdje je LEN duljina pojedinog niza
  5.  
  6.     Datum: 2013-02-23
  7.    
  8.     Autor: Hrvatski savez informatičara
  9.  
  10.     Ponuđeno rješenje: Kristijan Burnik, udruga informatičara Božo Težak
  11.  
  12.     Gmail: kristijanburnik
  13.  
  14. */
  15. #include <iostream>
  16. #include <cstdlib>
  17. #include <algorithm>
  18. #include <cmath>
  19. #include <vector>
  20. #include <set>
  21. #include <map>
  22. #include <stack>
  23. #include <queue>
  24.  
  25.  
  26. using namespace std;
  27.  
  28. bool ispravan(string s) {
  29.  
  30.     stack<char> stog;
  31.    
  32.     for (int i = 0 ; i < s.size(); i++) {
  33.         char procitani = s[i];
  34.         if (stog.empty()) {
  35.             stog.push(procitani);    
  36.         } else {
  37.             if ( stog.top() == procitani ) {
  38.                 stog.pop();    
  39.             } else {
  40.                 stog.push(procitani);    
  41.             }
  42.         }
  43.     }
  44.    
  45.     return stog.empty();
  46. }
  47.  
  48. int main() {
  49.     int n;
  50.     cin >> n;
  51.  
  52.     int ispravno = 0;
  53.     for (int i = 0 ; i < n; i++) {
  54.         string s;
  55.         cin >> s;
  56.         ispravno += ispravan( s );            
  57.     }
  58.    
  59.     cout << ispravno << endl;
  60.  
  61.  
  62.  
  63.    // system("pause");
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement