i don't understand the error or what's wrong with my code here's the code, i'm trying to solve problem Alice is rearranging her library. She takes the innermost shelf and reverses the order of books. She breaks the walls of the shelf. In the end, there will be only books and no shelf walls. Print the order of books.
Opening and closing walls of shelves are shown by '/' and '' respectively whereas books are represented by lower case alphabets.
int main()
{
string str;
cin>>str;
stack s;
int n = str.length();
if(str[0]!='/')
exit(1);
for(int i=0;i<n;i++)
{
if(str[i]=='/' or (str[i]>='a' and str[i]<='z'))
{
s.push(str[i]);
}
else
{
// reverse the string upto '/' in stack
string temp = NULL;
while(s.peak()!='/')
{
temp+=s.peak();
s.pop();
}
// remove '/' from stack's top
s.pop();
for(int j=0;j<temp.length();j++)
{
s.push(temp[j]);
}
}
}
string ans = "";
while(!s.isEmpty())
{
ans+=s.peak();
s.pop();
}
reverse(str.begin(), str.end());
cout<<ans;
return 0;
}