Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("paranteze1.in");
- ofstream fout("paranteze1.out");
- int n;
- char s[260];
- int Verifica(char s[])
- {
- int t,i;
- stack<char>st;
- t=strlen(s);
- if(t%2==1) return 0;
- for(i=0;i<t;i++)
- {
- if(s[i]=='(') st.push('(');
- else if(st.empty()) return 0;
- else st.pop();
- }
- if(st.empty()) return 1;
- return 0;
- }
- int main()
- {
- int i;
- fin>>n;
- for(i=1;i<=n;i++)
- {
- fin>>s;
- if(Verifica(s)) fout<<1<<"\n";
- else fout<<0<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement