zoukankan      html  css  js  c++  java
  • 数组右移问题

    1.刚开始的思路是要搞N个变量,觉得不好也没做太占空间,后来看了别人的办法,用时间换空间的办法

    #include <stdio.h>
    #include <stdlib.h>
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    int main() {
     int len=101,step,i,j,temp,count=0;
     scanf("%d",&len);
     scanf("%d",&step);
     int array[len];
     for(i=0;i<=len-1;i++)
     {
      scanf("%d",&array[i]);
      count++;
     }
     for(i=0;i<len;i++)
     {
      printf("%d ",array[i]);
     }
     for(i=0;i<step;i++)//循环的次数
     {
      
      temp=array[count-1];  //用一个变量存储最后一个数字,做N次循环
      for(j=len-1;j>=0;j--)
      {
       array[j]=array[j-1];
      }
       array[0]=temp;   
     }
     for(i=0;i<len;i++)
     {
      if(i==len-1)
      printf("%d",array[i]);
      else printf("%d ",array[i]);
     }
     system("pause");
     return 0;
      
    }
  • 相关阅读:
    质因数分解
    P1939 【模板】矩阵加速(数列)
    UVALive
    Python操作MySQL:pymysql模块
    Mysql数据库基础
    Redis管道和发布订阅
    Redis常用操作
    Redis操作集合,有序集合
    Redis操作list
    Redis操作hash
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/10310612.html
Copyright © 2011-2022 走看看