About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

সোমবার, ১৭ আগস্ট, ২০১৫

UVA 514 - Rails

#include <bits/stdc++.h>
#define sc(a) scanf("%d",&a)
#define scd(a,b) scanf("%d%d",&a,&b)
#define sct(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define READ freopen ("input.txt","r",stdin)
#define N 4

using namespace std;

typedef long long ll;
typedef vector<int>vc;

int main()
{
   // READ;
    int n;
    stack<int>st;
    queue<int>Q,R;
    while(~sc(n)&&n)
    {

        int t;
        while(cin>>t)
        {
            while(!Q.empty()) Q.pop();
            while(!st.empty()) st.pop();
            while(!R.empty()) R.pop();

            if(t==0)
            {
                printf("\n");
                break;

            }
            R.push(t);
            for(int i=2; i<=n; i++)
            {
                int x;
                cin>>x;
                R.push(x);

            }
            for(int i=1; i<=n; i++) Q.push(i);
            for(int i=0; i<n; i++)
            {
                int r=R.front();
              //  cout<<r<<endl;
                bool flag=false;
                if(st.size()!=0&&st.top()==r)
                {
                    flag=true;
                    st.pop();
                    R.pop();
                }
                else
                {
                    while(Q.size()>0)
                    {
                        if(Q.front()==r)
                        {
                            flag=true;
                            R.pop();
                            Q.pop();
                            break;

                        }
                        else
                        {
                            st.push(Q.front());
                            Q.pop();
                        }


                    }
                }
                if(flag==false) goto L;


            }
L:
         //cout<<st.size()<<" "<<Q.size()<<endl;
         if(st.size()==0&&Q.size()==0)   puts("Yes");
         else  puts("No");

        }




    }



    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন