1353:c Language Programming Tutorial (third Edition) After class exercise 10.4 time limit:1 Sec Memory limit:128 MB
submit:296 solved:219
[Submit] [Status] [BBS] Description have n integers, so that the previous number of sequential moves backward m position, the last m number into the first number of M, see figure. Write a function: To achieve the above function, in the main function input n number and output adjusted n number. The number of inputs input data n n Integer moved position moutput the number of n after the move, sample input
101 2 3 4 5 6 7 8 9 102
Sample Output
#include <stdio.h>Const intn=100000;intn,a[n],b[n],m;voidMove () { for(intI=0; i<m; i++) {b[m-1-i]=a[n-1-I.];//another array, from the back to the next, the last few numbers of a array first to make one side } for(inti=n-1; i>=0; i--) { if(i>=m) A[i]=a[i-m]; if(i<m) A[i]=b[i];//direct assignment to front of array a }}intMain () { while(SCANF ("%d", &n)! =EOF) { for(intI=0; i<n; i++) {scanf ("%d",&A[i]); } scanf ("%d",&m); Move (); for(intI=0; i<n; i++) {printf ("%d", A[i]); } printf ("\ n"); } return 0;}
C Language Programming Tutorial (third Edition) after class exercise 10.4