題目:定義字串的左旋轉操作,把字串前面的若干個字元移動到字串的尾部。
要求:對長度為n的字串操作的時間複雜度為o(n),輔助記憶體為o(1)。
舉例:把字串abcdef左旋轉2位得到字串cdefab。
答:
#include "執行介面如下:stdafx.h
"#include
using
namespace
std;
void swap(char *str, int begin, int
end)
}void rotate(char *str, int length ,int
m) swap(str,
0, m - 1
); swap(str, m, length - 1
); swap(str,
0, length - 1);}
int _tmain(int argc, _tchar*argv)
左旋轉字串
題目 定義字串的左旋轉操作 把字串前面的若干個字元移動到字串的尾部。如把字串abcdef左旋轉2位得到字串cdefab。請實現字串左旋轉的函式。要求時間對長度為n的字串操作的複雜度為o n 輔助記憶體為o 1 思想 旋轉三次 include include using namespace std v...
左旋轉字串
package com.string 旋轉字串 q 26 左旋轉字串 題目 定義字串的左旋轉操作 把字串前面的若干個字元移動到字串的尾部。如把字串abcdef左旋轉2位得到字串cdefab。請實現字串左旋轉的函式。要求時間對長度為n的字串操作的複雜度為o n 輔助記憶體為o 1 public cla...
左旋轉字串
如abc,左旋1得到bca,左旋2得到cab o n k 的演算法 include using namespace std include include include include include include include include include include int main...