>   3 4 5 1 2  ..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

還是一道旋轉(zhuǎn)數(shù)組的題目

發(fā)布時間:2020-04-06 11:57:00 來源:網(wǎng)絡(luò) 閱讀:229 作者:wzdouban 欄目:編程語言
 /*
 關(guān)于這 數(shù)組偏移
 1 2 3 4 5   3---->>   3 4 5 1 2
 n =5  返回 2
 */
 
#include <bits/stdc++.h>
using namespace std;
 int a[]={1,2,3,4,5};
 int n=5;
 int count=3;
int fun(int n,int a[],int count,int len)//不給數(shù)組長度真的不好做 ,JAVA是能由數(shù)組直接拿
{
     int b[2*len];  int ret=0;
     for(int i=0;i<2*len;i++)
      {
          b[i]=a[i%len];//cout<<b[i]<<"  "; 空間換時間,思考的一種方法               
      }
    for(int i=count-1;i<count-1+len;i++)  
      {
        cout<<b[i]<<"  ";   //即輸出 旋轉(zhuǎn)后的數(shù)組
        if(b[i]==n) 
          {
              ret=i-count+1; 
          }
      }
      cout<<endl;
      return ret;
}
// 1 2 3 4 5 1 2 3 4 5
//     ---------
int main()
{
    cout<<fun(5,a,3,5)<<endl; 
	cout << "Hello,C++ world of AnycodeX!" << endl;
	return 0;
}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI