题意:两根绳子交叉数次,判断展开后是否会打结
链接:http://codeforces.com/problemset/problem/343/B
思路:类似括号配对问题,用栈处理下即可
注意点:无
以下为AC代码:
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged |
---|---|---|---|---|---|---|---|---|
9732235 | Practice: luminous11 | 343B - 51 | GNU C++11 | Accepted | 60 ms | 552 KB | 2015-02-06 02:32:05 | 2015-02-06 02:32:05 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
int main()
{
ios::sync_with_stdio( false );
string str;
while ( cin >> str ){
stack<int> s;
for ( int i = 0; i < str.size(); i ++ ){
int tmp;
if ( str[i] == '+' ){
tmp = 1;
}
else{
tmp = 0;
}
if ( s.empty() ){
s.push ( tmp );
}
else{
if ( s.top() == tmp ){
s.pop();
}
else{
s.push ( tmp );
}
}
}
if ( ! s.empty() ){
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
}
}
return 0;
}