Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- // Alice Library - https://code.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/algorithm/katrina-and-library-c2ed51f3/
- int main() {
- string s;
- cin>>s;
- int n = s.length();
- stack<char> st;
- for(int i=0;i<n;i++)
- {
- if(s[i]=='/' or (s[i]>='a' and s[i]<='z'))
- {
- st.push(s[i]);
- }
- else
- {
- // reverse the string upto '/' in stack
- string temp = "";
- while(st.top()!='/')
- {
- temp+=st.top();
- st.pop();
- }
- // remove '/' from stack's top
- st.pop();
- for(int j=0;j<temp.length();j++)
- {
- st.push(temp[j]);
- }
- }
- }
- string ans = "";
- while(!st.empty())
- {
- ans+=st.top();
- st.pop();
- }
- reverse(ans.begin(), ans.end());
- cout<<ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement