1.『基礎題庫』- a045- #include<bits/stdc++.h>
- #include<stack>
- using namespace std;
- bool isbracket(string c)
- {
- stack<char>s;
- for(int i=0;i<c.size();i++)
- {
- if(c[i]=='['||c[i]=='('||c[i]=='{')
- {
- s.push(c[i]);
- }
- else if(c[i]==']'||c[i]==')'||c[i]=='}')
- {
- if(s.empty()||
- (c[i]=='}'&&s.top()!='{')||
- (c[i]==']'&&s.top()!='[')||
- (c[i]==')'&&s.top()!='('))
- return false;
- s.pop();
- }
- }
- return s.empty();
- }
- int main()
- {
- string line;
- int count=0;
- while(getline(cin,line)&& count<20)
- {
- if(line.empty())break;
- if(line.size()>150)continue;
- cout<<(isbracket(line)?"yes":"no")<<'\n';
- count++;
- }
- return 0;
- }
複製代碼 2. APCS 觀念題 (考古題):
10510 - 1310510 - 14 |