View Code of Problem 79

#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {

	//有n个整数,使前面各数顺序向后移m个位置,最后m个数变成前面m个数,
	//见图。写一函数:实现以上功能,在主函数中输入n个数和输出调整后的n个数。
	//9 10 1 2 3 4 5 6 7 8 
	//  1 2 3 4 5 
	//  4 5 1 2 3 
	int i = 0;
	int n, m ;
	scanf("%d",&n);
	scanf("%d" , &m);
	int arr [n];	//n =5
	int arr2 [m];	//m=2
	//输入n个数字 
	for( i = 0 ; i < n ; i++){
		scanf("%d" , &arr[i]);
	}
	//把 
	int j = m; 
	for(  ; i > m ;i--){	//i=5
		arr2[--j] = arr[i - 1];
	}
	
	for(j = 0;j<m;j++){
		printf("%d\t",arr2[j]);
	}
	printf("\n-----------------\n");
	
	
	for(  ; i >= 0 ; i--){	//i=2
		arr[ i + m ] = arr[i];
	}
	j = 0;
	for(  i=0 ;  i< m ;i++ ){	//i=0
		arr[i] = arr2[j++];
	}
	
	for( i = 0 ; i< n ; i++){
		printf("%d\t" , arr[i]);
	}
	
	return 0 ;
}












Double click to view unformatted code.


Back to problem 79