Source code:
#include<iostream>
#include<string>
using namespace std;
void final_string(string& a){
int count = 0;
for(int i = a.length()-1;i >= 0;i--){
if(a[i] == '#'){
count++;
a.erase(a.begin()+i);
}
else if(a[i] != '#' && count > 0){
a.erase(a.begin() + i);
count--;
}
}
return;
}
int main()
{
cout<< "first string with #: ";
string a = "";
cin >> a;
cout << "second string with #: ";
string b = "";
cin >> b;
final_string(a);
final_string(b);
cout << "first string is " << a << endl;
cout << "second string is " << b << endl;
if(a==b){
cout << "both are same" << endl;
}
else{
cout << "they are different" << endl;
}
return 0;
}
0 Comments
Post a Comment