-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackSpaceString.cpp
More file actions
41 lines (41 loc) · 952 Bytes
/
backSpaceString.cpp
File metadata and controls
41 lines (41 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
bool backspaceCompare(string S, string T) {
int solidL1 = -1,solidL2 = -1;
for(int index = 0;index<S.length();++index){
if(S[index]=='#' && solidL1!=-1){
solidL1-=1;
}
else if(S[index]!='#'){
S[solidL1+1] = S[index];
++solidL1;
}
}
for(int index = 0;index<T.length();++index){
if(T[index]=='#' && solidL2!=-1){
solidL2-=1;
}
else if(T[index]!='#'){
T[solidL2+1] = T[index];
++solidL2;
}
}
if(solidL1!=solidL2){
return false;
}
if(solidL1==-1 && solidL2){
return true;
}
for(int i=0;i<solidL1;++i){
if(S[i]!=T[i]){
return false;
}
}
return true;
}
int main(){
std::string str1, str2;
std::cin>>str1>>str2;
std::cout<<backspaceCompare(str1, str2)<<std::endl;
return 0;
}