We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Circular Array Rotation
  5. Discussions

Circular Array Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • Stephen26 4 years ago+ 0 comments

    no Rotation but still does the job :v CHECK THIS out c++ lovers

    im noob in coding so i wrote it so big :(

     int b,n,k,q,ans=0;
    cin>>n>>k>>q;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        if(k==n){
            for(int i=0;i<q;i++)
        {
         cin>>b;
         cout<<a[b]<<endl;
        }
        }
        else if(k>n)
        { while(k>n)
            k=k-n;
            for(int i=0;i<q;i++)
            {
                ans=n-k;
                cin>>b;
                ans+=b;
                if(ans>n-1)
                    ans-=n;
                cout<<a[ans]<<endl;
            }
        } else if(k<n)
            {
    
               for(int i=0;i<q;i++)
            {
                ans=n-k;
                cin>>b;
                ans+=b;
                if(ans> n-1)
                    ans-=n;
                cout<<a[ans]<<endl;
            }
            }
    return 0;
    

    }

    0|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature