Friday, October 21, 2016

11988 - Broken Keyboard (a.k.a. Beiju Text) solution

Problem link-click here

you have to go through the term List in C++ to solve this problem easily. please visit the link below to learn details about list:

list in c++

an accepted code is as follows:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    string str;

    while(cin>>str)
    {
        list<char> l;
        list<char>::iterator iter;
        int i=0;

        iter=l.end();

        while(str[i])
        {
            if(str[i]=='[')
            {
                iter=l.begin();
            }
            else if(str[i]==']')
            {
               iter=l.end();
            }
            else
            {
                l.insert(iter,str[i]);
            }
            i++;
        }

        for(iter=l.begin();iter!=l.end();iter++)
        {
            cout<<*iter;
        }

        cout<<endl;
    }

    return 0;
}

No comments:

Post a Comment