字母排序問題(c 實現)

2022-01-11 19:40:17 字數 827 閱讀 3371

描述:編寫乙個程式,當輸入不超過60個字元組成的英文文字時,計算機將這個句子中的字母按英文本典字母順序重新排列,排列後的單詞的長度要與原始句子中的長度 相同。例如:

輸入:輸出:

並且要求只對a到z的字母重新排列,其它字元保持原來的狀態。

分析:難點在待排序列中混有不相干的字元,我用的是氣泡排序法,在大寫字母間進行比較,用乙個函式返回和最大值交換的字母的下標。

1 #include2 #include

3using

namespace

std;45

//返回第k位前的乙個大寫字母的下標

6int cal(string a, intk)7

13return -1;14

}15void exchange(string& a, int x, int

y)16

19int

main()

2029

int start;//

排序的初始值

30for (int i = 0;; i++)

3136}37

int swap = cal(a,a.size()-1);//

要交換的字母下標

38for (int i = 0; i < n; i++)

3946

exchange(a, max, swap);

47 swap = cal(a, swap - 1

);48

}49 cout << a <50 system("

pause");

51return0;

52 }

MySQL 字母數字混合排序問題

資料庫有列字段 column zz 1 tt 2 tt 19 zz 12 zz 3 zz 2 zz 9 tt 1 tt 3 tt 4 tt 5 有位小鵬友要我先按字母排序,再按數字排序,方便檢視。顯示為 column tt 1 tt 2 tt 3 tt 4 tt 5 tt 19 zz 1 zz 2 ...

js實現漢字轉拼音(解決首字母排序問題)

漢字有21個聲母 b,p,m,f,d,t,n,l,g,k,h,j,q,x,zh,ch,sh,r,z,c,s 有韻母24個,其中單韻母有6個 a,o,e,i,u,v,復韻母有18個 ai ei,ui ao,ou,iu ie,ve,er,an en in,un vn ang,eng,ing ong 假設...

實現按指定字母序進行排序

給定 n 個字串 abc dca add ae 最終排序結果為 abc ae add dca include include include include char need arr abcdefghijklmnopqrstuvwxyz typedef char words words worda...