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;}