Wednesday, January 3, 2018

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

problem link:

Discuss: this is simple list implementation problem.if you know list then you can it without any trouble. just input the line in a string and then if  '[' in string then change the iterator of string in begin and if you found ']' then change the iterator of string in end.  and else just insert the element in the list.

try your self before see the code




#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,cnt=0,flag=0;
    char str[100001];

    while(cin >>str)
    {
         list<char> lst;
        if(!strcmp(str,"-1"))
            break;
        list<char>::iterator p=lst.begin();
        int b=0,e=0;
       n=strlen(str);
       for(i=0;i<n;i++)
       {
           if(str[i]=='[')
           {
              p=lst.begin();
           }
           else if(str[i]==']')
           {
                p=lst.end();
           }
           else
            lst.insert(p,str[i]);

       }
       p=lst.begin();
       while(p!=lst.end())
       {
           cout <<*p;
           p++;

       }
       cout <<endl;
    }
    return 0;
}

No comments:

Post a Comment