Analysis of Pat computer problems in Zhejiang University 1008. Right Shift of array element loop (20)

Source: Internet
Author: User
1008. array element loop right shift problem (20) Time Limit 400 MS
The memory limit is 32000 kb.
Code length limit: 8000 B
Criterion

An array A contains n (n> 0) integers. If another array is not allowed, the position of each integer is shifted to M (M> = 0, that is ...... An-1) transform to (AN-M ...... An-1 A0 A1 ...... AN-M-1) (the last M number cycle moves to the m position at the beginning ). If you need to consider how to design a mobile method to minimize the number of APP data moves?

Input Format:Each input contains a test case. Input N (1 <= n <= 1st), m (M> = 0), and input n integers in row 100, are separated by spaces.

Output Format:Output the integer sequence after the right shift of M digits in a row, which is separated by spaces. No extra spaces are allowed at the end of the sequence.

Input example:

6 21 2 3 4 5 6

Output example:

5 6 1 2 3 4
 
#include<iostream>#include <list>using namespace std;int main(){  int M,N,t,i;  bool flag=false;  list<int> mylist;  list<int>::iterator it;  cin>>M>>N;  while(M--)  {    cin>>t;    mylist.push_back(t);  }  while(N--)  {    t = mylist.back();    mylist.pop_back();    mylist.push_front(t);  }  for (it=mylist.begin();it!=mylist.end();it++)  {    if (flag)    cout<<" ";    else    flag=true;    cout<<*it;  }  cout<<endl;  //system("pause");  return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.