練習8 字串排序

2021-09-10 08:53:03 字數 372 閱讀 6579

目的:輸入任意長度字串,使其按a~z(或者說是按ascii碼順序排列)

這裡使用字元陣列儲存,使用選擇排序的方法進行排序,關於選擇排序,可參考我之前的部落格練習7,有詳細說明

這裡根據字元對應的ascii碼的十進位制數進行排序,關於ascii碼不做過多解釋.

#include#includevoid swap(char *a,char *b)        //交換函式

using namespace std;

int main()

} }cout<<"排序後的字串為:"

return 0;

}

8 字串函式

right left 可從列中選出指定數量的字元 right location,2 location 欄位 substring index 可擷取部分字段值 substring index location,1 尋找第乙個逗號,然後擷取之前的內容 substring your string,star...

(59)字串練習

一 模擬trim方法去除兩端的空格 bh public static void simulatetrim if start end 若為空,則start先執行,等於end end後執行,end 1,所以start end為空串 sop 這是個只含空格的字串 else sop 哈哈 s.substri...

9 字串排序

字串排序 time limit 1000 ms memory limit 65536 kb description 輸入3個字串,按字典序從小到大進行排序。input 輸入資料有一行,分別為3個字串,用空格分隔,每個字串長度不超過100。output 輸出排序後的三個字串,用空格分隔。sample ...