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

Please explain where is the problem
Posted by monteg 4 Jan 2012 17:51
#include <iostream>
#include <string>
using namespace std;
void main()
{
    string shifr;
    cin >> shifr;
    for (int n = 0;n<shifr.length();n++)
    {
    for (int i = 0;i<shifr.length()-1;i++)
    {
        if(shifr[i]==shifr[i+1])
        {
            shifr.erase(i,2);
        }
    }
    }
    cout << shifr << endl;
}

I have got crash on test 2
Re: Please explain where is the problem
Posted by VNXtreMe 6 Jan 2012 16:28
First of all you will get TLE for your solution.
Just use the Stack data structure and insert each characters one by one from the input string by comparing them with the lastly pushed character. If they match, then pop it off that lastly pushed character. Then printout the stack in reverse. That's all :)