码迷,mamicode.com
首页 > 编程语言 > 详细

算法竞赛入门经典(第六章)

时间:2014-11-01 22:57:44      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   for   sp   

习题6-1,UVa673,Time:11.1

bubuko.com,布布扣
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<string>
 6 #include <stack>
 7 using namespace std;
 8 int main() {
 9     int Case;
10     string str;
11     bool flag;
12     scanf("%d",&Case);
13     for(int c = 1; c <= Case; c++)
14     {
15         stack<char>q;
16         flag = true;
17         cin>>str;
18         for(int i = 0; i < str.length(); i++)
19         {
20             if(q.size() == 0 || str[i]==( || str[i]==[)        q.push(str[i]);
21             else
22             {
23                 if((str[i]==) && q.top()==() || (str[i]==] && q.top()==[))
24                 {
25                     q.pop();
26                 }
27                 else
28                 {
29                     flag = false;
30                     break;    
31                 }
32             }
33         }
34         if(flag==false || q.size())        cout<<"NO"<<endl;
35         else     cout<<"YES"<<endl;
36     }
37     return 0;
38 }
View Code

 

算法竞赛入门经典(第六章)

标签:style   blog   http   io   color   os   ar   for   sp   

原文地址:http://www.cnblogs.com/you-well-day-fine/p/4067814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!