1 solutions
-
0
C :
#include<stdio.h> #include<string.h> int main(void) { int left=0,right=0,t=0; char string[300]; scanf("%s",string); for(int i=0;i<strlen(string);i++) { if(string[i]=='(') { left++; t++; } if(string[i]==')') { right++; if(t)t--; } } if(left==right&&t==0) printf("YES\n"); else { printf("NO\n"); } }C++ :
#include<iostream> #include<cstring> #include<cstdio> using namespace std; string s; bool my_judge(string); int main() { //freopen("stack10.in","r",stdin); //freopen("stack10.out","w",stdout); getline(cin,s); if(my_judge(s))cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; } bool my_judge(string c) { int top=0,i=0; while(c[i]!='@') { if(c[i]=='(')top++; if(c[i]==')') { if(top>0)top--; else return false; } ++i; } if(top==0)return true; else return false; }Pascal :
program acm21147; var ch:char; j:integer; begin while not eoln do begin read(ch); if ch='(' then begin inc(j); end; if (ch=')') then begin dec(j); end; if j<0 then begin writeln('NO'); halt; end; end; if j<>0 then writeln('NO') else writeln('YES'); end.Python :
# coding=utf-8 import queue s=queue.LifoQueue() x=input() for c in x: if c=='(': s.put(c) elif c==')': if not s.empty(): s.get() else: s.put(1) break if s.empty(): print('YES') else: print('NO')
- 1
Information
- ID
- 20060
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 4
- Tags
- # Submissions
- 75
- Accepted
- 32
- Uploaded By