ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1654. Cipher Message

Code not producing any output?
Posted by Naman Sharma 25 Mar 2020 19:56
#include<bits/stdc++.h>
using namespace std;
stack<char> S;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len;i++)
    {
        char c;
        if(S.empty())
            c = 0;
        else
            c = S.top();
        if(c == s[i])
            S.pop();
        else
            S.push(c);
    }
    string ans = "";
    len = S.size();
    for(int i = 0; i < len;i++)
    {
        char c = S.top();
        ans += c;
        S.pop();
    }
    reverse(ans.begin(),ans.end());
    cout << ans;
}
Re: Code not producing any output?
Posted by Lolimz Alibaa 20 May 2020 13:21
You should do S.push(s[i]) in your else clause inside the for loop.