字符串首字母排序
来源:互联网 发布:java流程图制作软件 编辑:程序博客网 时间:2024/06/06 14:27
根据字符串的首字母进行排序。
例如:“我的名字”,提取为“WDMZ”后进行排序。“11我的ab名字”,提取为"11WDabMZ"后进行排序。
void FirstLetter(int nCode, CString& strLetter){if (nCode >= 1601 && nCode < 1637) strLetter = _T("A");if (nCode >= 1637 && nCode < 1833) strLetter = _T("B");if (nCode >= 1833 && nCode < 2078) strLetter = _T("C");if (nCode >= 2078 && nCode < 2274) strLetter = _T("D");if (nCode >= 2274 && nCode < 2302) strLetter = _T("E");if (nCode >= 2302 && nCode < 2433) strLetter = _T("F");if (nCode >= 2433 && nCode < 2594) strLetter = _T("G");if (nCode >= 2594 && nCode < 2787) strLetter = _T("H");if (nCode >= 2787 && nCode < 3106) strLetter = _T("J");if (nCode >= 3106 && nCode < 3212) strLetter = _T("K");if (nCode >= 3212 && nCode < 3472) strLetter = _T("L");if (nCode >= 3472 && nCode < 3635) strLetter = _T("M");if (nCode >= 3635 && nCode < 3722) strLetter = _T("N");if (nCode >= 3722 && nCode < 3730) strLetter = _T("O");if (nCode >= 3730 && nCode < 3858) strLetter = _T("P");if (nCode >= 3858 && nCode < 4027) strLetter = _T("Q");if (nCode >= 4027 && nCode < 4086) strLetter = _T("R");if (nCode >= 4086 && nCode < 4390) strLetter = _T("S");if (nCode >= 4390 && nCode < 4558) strLetter = _T("T");if (nCode >= 4558 && nCode < 4684) strLetter = _T("W");if (nCode >= 4684 && nCode < 4925) strLetter = _T("X");if (nCode >= 4925 && nCode < 5249) strLetter = _T("Y");if (nCode >= 5249 && nCode < 5590) strLetter = _T("Z");}
int CompareCATALOG_NAME(const void *arg1, const void *arg2){LPSECURITY_BOOK sb1 = (LPSECURITY_BOOK)arg1;LPSECURITY_BOOK sb2 = (LPSECURITY_BOOK)arg2;CString strTempBook1 = sb1->itemCataName;CStringstrTempBook2 = sb2->itemCataName;int iLength1, iLength2;char cName1[1024];char cName2[1024];BOOL ifChinese1 = FALSE;BOOL ifChinese2 = FALSE;CString cLetterName1, strTemp1;CString cLetterName2, strTemp2;unsigned char ucHigh1;unsigned char ucLow1;DWORD sum1;unsigned char ucHigh2;unsigned char ucLow2;DWORD sum2;iLength1 = WideCharToMultiByte(CP_ACP, 0, strTempBook1, -1, NULL, 0, NULL, NULL);WideCharToMultiByte(CP_ACP, 0, strTempBook1, -1, cName1, iLength1, NULL, NULL);iLength2 = WideCharToMultiByte(CP_ACP, 0, strTempBook2, -1, NULL, 0, NULL, NULL);WideCharToMultiByte(CP_ACP, 0, strTempBook2, -1, cName2, iLength2, NULL, NULL);for (int i = 0; i < iLength1; i++){ucHigh1 = (unsigned char)cName1[i];if (ucHigh1 < 128){cLetterName1 += cName1[i];continue;}ucLow1 = (unsigned char)cName1[i + 1];sum1 = ((ucHigh1 - 0xa0) * 100) + ucLow1 - 0xa0;if (ucHigh1 > 128 && ucLow1 > 128){FirstLetter(sum1, strTemp1);cLetterName1 += strTemp1;}i++;}for (int i = 0; i < iLength2; i++){int j = 0;ucHigh2 = (unsigned char)cName2[i];if (ucHigh2 < 128){cLetterName2 += cName2[i];continue;}ucLow2 = (unsigned char)cName2[i + 1];sum2 = ((ucHigh2 - 0xa0) * 100) + ucLow2 - 0xa0;if (ucHigh2 > 128 && ucLow2 > 128){FirstLetter(sum2, strTemp2);cLetterName2 += strTemp2;}i++;}return _tcscmp(cLetterName1.GetBuffer(0), cLetterName2.GetBuffer(0));}
qsort(m_pCatalogName, m_dwCatalogName, sizeof(SECURITY_BOOK), CompareCATALOG_NAME);
0 0
- 字符串首字母排序
- ios 字符串首字母排序
- 字符串首字母排序加密
- java中中文字符串按首字母排序
- 根据字符串首字母分组并内部排序
- 07.将字符串按首字母排序
- php将字符串按照首字母顺序排序
- Android 获取字符串首字母,并对字符串列表进行排序。
- android 中英混合字符串数组按首字母进行排序
- 用系统方法提取字符串首字母并进行排序
- 编写一个程序 输入字符串 直到遇到NULL 实现字符串的首字母排序(图)
- 中文首字母 排序
- 中文首字母 排序
- 数据库汉字首字母排序
- php按首字母排序
- pinyin中文首字母排序
- Android 汉字首字母排序
- ios 人名首字母排序
- iOS开发——蒙版(引导介绍遮罩)工具类
- 查错 (拓扑排序+堆维护)
- POJ-1442-Black Box
- Windows批处理 - 给自己写个库(3. INI文件的读取)
- scala的函数定义、流程控制和异常处理
- 字符串首字母排序
- ActiveMQ实现负载均衡+高可用部署方案
- linux下解压tgz文件
- explicit
- 蓝桥之圆面积
- IP头、TCP头、UDP头详解以及定义(全)
- LeetCode No.78 Subsets
- openwrt环境搭建
- 解决子div撑不开父div