#include<iostream>
#include<stack>
using namespace std;
int main()
{
string s;
string t;
cin >> s;
cin >> t;
stack<char> s1;
stack<char> t1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') {
if (s1.empty()) {
continue;
}
else {
s1.pop();
}
}
else {
s1.push(s[i]);
}
}
for (int i = 0; i < t.size(); i++) {
if (t[i] == '#') {
if (t1.empty()) {
continue;
}
else {
t1.pop();
}
}
else {
t1.push(t[i]);
}
}
if (s1.size() != t1.size()) {
cout << "false";
}
else if (s1.empty() && t1.empty()) {
cout << "true";
}
else {
int flag = 1;
for (int i = 0; i < s1.size(); i++) {
if (s1.top()!=t1.top()) {
flag = 0;
break;
}
s1.pop();
t1.pop();
}
if (flag == 0) {
cout << "false";
}
else {
cout << "true";
}
}
return 0;
}
Leetcode-844
最新推荐文章于 2024-11-09 23:37:51 发布