好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

1153: 零起点学算法60——元素前移1位

1153: 零起点学算法60——元素前移1位

Time Limit: 1 Sec   Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 859   Accepted: 574
[ Submit ][ Status ][ Web Board ]

Description

将数组所有元素前移一位(最前面的元素移到最后)然后输出移动后的数组

 

Input

多组测试数据,每组
第一行输入一个整数n(不大于20)
第二行输入n个整数

 

Output

输出前移一位后的数组

 

Sample Input

 

 4
1 2 3 4 

 

Sample Output

 2 3 4 1
 

 

Source

零起点学算法

 

  1  #include<stdio.h>
  2   int   main(){
   3       int  n,a[ 20 ],b[ 20  ];
   4       while (scanf( "  %d  " ,&n)!= EOF){
   5           for ( int  i= 0 ;i<n;i++ ){
   6              scanf( "  %d  " ,& a[i]); 
   7           }
   8      
  9       for ( int  i= 1 ;i<n;i++ ){
  10          b[i- 1 ]= a[i];
  11       }
  12      b[n- 1 ]=a[ 0  ];
  13      
 14       for ( int  i= 0 ;i<n- 1 ;i++ ){
  15          printf( "  %d   "  ,b[i]); 
  16       }
  17      printf( "  %d\n  " ,b[n- 1  ]);
  18       }
  19       return   0  ;
  20  } 

 

查看更多关于1153: 零起点学算法60——元素前移1位的详细内容...

  阅读:39次