Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zadatak: Esej
- Složenost: o(LEN) gdje je LEN duljina pojedinog niza
- Datum: 2013-02-23
- Autor: Hrvatski savez informatičara
- Ponuđeno rješenje: Kristijan Burnik, udruga informatičara Božo Težak
- Gmail: kristijanburnik
- */
- #include <iostream>
- #include <cstdlib>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- using namespace std;
- bool ispravan(string s) {
- stack<char> stog;
- for (int i = 0 ; i < s.size(); i++) {
- char procitani = s[i];
- if (stog.empty()) {
- stog.push(procitani);
- } else {
- if ( stog.top() == procitani ) {
- stog.pop();
- } else {
- stog.push(procitani);
- }
- }
- }
- return stog.empty();
- }
- int main() {
- int n;
- cin >> n;
- int ispravno = 0;
- for (int i = 0 ; i < n; i++) {
- string s;
- cin >> s;
- ispravno += ispravan( s );
- }
- cout << ispravno << endl;
- // system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement