按拼音或者笔画排序你的字符串

Python实现获取汉字笔画数,根据汉字笔画数量排序 起因 本人现在所在的公司是由香港人开办的,也是做做香港业务,一个车辆管理系统后台,也包括司机等人员管理。突然有一天,老板说我们的列表找司机不够人性化,不符合用户习惯。因为我们Python对中文排序默认是按照Unicode编码来排序的,很正常嘛,一般都喜欢希望按照拼音来排序。然后我就惊呆了:香港人不会拼音… 那按照五笔排序?也不是,他们要按照汉字的笔画数量排序,笔画少的,排在前面。 额…(靓仔语塞.jpg) 不过既然老板需要,那还是要搞起来的 如果不是做香港业务,我可能永远也不会想到中文排序除了【按照拼音排 阅读详情
 很多人会很好奇,怎么数据库能够根据拼音排序的?网上能搜到很多网友自己写的处理按拼音排序的模块。
GB2312的一级汉字确实是按拼音排列的,我们可以简单的比较它们的编码,但是二级汉字呢?如果你的程序是使用Unicode字符串的呢?

不用担心,Windows I18N API已经给我们提供了相关的函数来实现这一切,你所需要做的就是传入一个合适的参数。

下面的函数会将GBK中所有的汉字按拼音或者笔画序输出到控制台,非常简单,对吗?

#include <windows.h>
#include <algorithm>
#include <cstdio>

char Buf[65536][3];
char *BufT[65536];

bool Comp(const char *str1,const char *str2)
{
    //SORT_CHINESE_PRCP    拼音
    //SORT_CHINESE_PRC    笔画
    int t=::CompareString(MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRCP),0,str1,-1,str2,-1);
    return t<2;
}

int main()
{
    //生成GBK码表
    int n=0;
    for (int i=0x81;i<=0xFE;++i)
    {
        for (int j=0x40;j<=0x7E;++j) {
            Buf[n][0]=(char)i;
            Buf[n][1]=(char)j;
            ++n;
        }
        for (int j=0x80;j<=0xFE;++j) {
            Buf[n][0]=(char)i;
            Buf[n][1]=(char)j;
            ++n;
        }
    }

    for (int i=0;i<n;++i) BufT[i]=&Buf[i][0];
    std::sort(&BufT[0],&BufT[n],Comp);
    for (int i=0;i<n;++i) printf("%s",BufT[i]);
}

附上一篇非常详尽的描述Windows I18N API的文章:
http://www.woodenhead.org/microsoft/International%20Programming%20for%20Microsoft%20Windows/9.htm
姓氏笔画排序应用完全版 最好的姓氏笔画排序软件,大家多用多评分! 立即下载

相关推荐

汉字笔画和拼音

有2个工程,ss是笔画的工程,输入汉字得到汉字的笔画数;第2个是拼音的工程,输入汉字得到汉字的拼音。很拥有的工具。

Python实现获得所有拼音为某个拼音的所有汉字

好久没有写博客了,这几年的开发让我感受良多,同时我也感觉到了我自己成长的还不够。所以,以后这里将会有我个人所有的项目经验总结,但是更多的是自我的反思 1、项目越急,越不要急:项目急了,我就会慌起来,然后改完之后很多报错。改一个BUG,出来好几个新BUG。所以,还是建议各位,每次做东西的时候,思考的全面一点,测试的全面一点。就比如有一个控制房间的开关,加了开关之后,开关两个状态都要测试一下。说到底还是不够心细 ...

levosam的博客 2137

汉字笔画 输入汉字 输出笔画数 VC++ 含全部源码

汉字笔画 输入汉字 输出笔画数 VC++ 含全部源码 汉字笔画 输入汉字 输出笔画数 VC++ 含全部源码

C++使用汉字排序(按照拼音排序)

#include "stdafx.h" void   FirstLetter(int   nCode,   char&   strRet);   void   GetFirstLetter(char*   strName,   char*   strFirstLetter,int nLen)   {   unsigned char   ucHigh,   ucLow;   int

wangkr的专栏 1万+

vb全功能汉字转拼音

用vb做的,自动把汉字转换成拼音,握有的汉字都能成功转换,简单功能强大

按姓氏笔画排序.rar

按姓氏笔画排序.rar按姓氏笔画排序.rar

C#中文排序(拼音和笔画)

【转】C#中文排序(拼音和笔画)using System; using System.Globalization; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] arr = { "3","1","2","b","c","a","B

我的专栏 4783

vb 输入汉字获取拼音

这是一个在文本框中输入汉字就可以获取该汉字拼音字母的一个小程序。。

python 拼音排序_Python实现针对中文排序的方法

本文实例讲述了Python实现针对中文排序的方法。分享给大家供大家参考,具体如下:Python比较字符串大小时,根据的是ord函数得到的编码值。基于它的排序函数sort可以很容易为数字和英文字母排序,因为它们在编码表中就是顺序排列的。>> print ','< '1' pyB:return 1elif pyA < pyB:return 0else:bhA=eval(searchdict(dic_b...

weixin_39769984的博客 628

姓氏笔画排序

姓氏笔画排序,非常省事,一款非常好用的小程序,建议使用,屡试不爽。

如何在高版本的ubuntu系统里安装gcc4.1.2

1、下载安装包,一共五个http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-4.1/,根据计算机系统位数   进行下载,64位下载amd64结尾的。开头分别是cpp-4.1_4.1.2、g++-4.1_4.1.2、gcc-4.1-base_4.1.2、gcc-     4.1_4.1.2、libstdc++6-4.1 2、使用sudo d

lsr_fighting的博客 1941

Oracle中对查询条件进行按拼音/笔画/部首order by排序

nlssort函数的作用是对字段排序,字符串类型的 1.按拼音排序: select * from MEMBER t order by NLSSORT(t.b,'NLS_SORT = SCHINESE_PINYIN_M') 2.按笔画排序: select * from MEMBER t order by NLSSORT(t.b,'NLS_SORT = SCHINESE_STROKE_M') 3.按部首排序: select * from MEMBER t orde...

y2020520的博客 395

STM32F103 实例应用(10)——I2C读写24C32

一、应用简介 本文介绍24C32的读写,基于野火的软件I2C程序。 board_i2c.h /**=========================================================================== @file board_i2c.h @brief 本文件是用于I2C驱动 @author 青梅煮久 @version r0.1 @date 2021/01/13 -------------------------.

qq_34118600的博客 3455

中文序列按笔画排序

问题:给定一串含中文的序列,按首字符的笔画数排序 因为默认是按拼音来排序的, 借助Globalization命名空间,包含定义区域性相关信息的类,这些信息包括语言,国家/地区,正在使用的日历,日期、货币和数字的格式模式,以及字符串的排序顺序。 我们可以使用这些类编写全球化(国际化)应用程序。 CultureInfo 类,提供有关特定区域性的信息(对于非托管代码开发,则称为“区域设置”)。

Peter-H 2229

短视频mssdk中get_token协议逆向与加密流程深度解析

本文深度解析了短视频mssdk中get_token协议的逆向分析与加密流程。通过抓包、Frida Hook、静态分析等手段,详细拆解了协议数据的Protobuf结构、设备信息采集来源,并重点剖析了其核心加密链路:zlib压缩、自定义TEA算法与AES-CBC加密,最终实现完整的协议模拟。

flower的专栏 572

骚操作,尝试使用Xilinx XVC协议,通过Jlink来下载调试Xilink zynq FPGA芯片

最近一直在玩zynq芯片,手头使用的Xilinx Platform USB Cable 下载线真是辣鸡,速度慢如蜗牛,每次下载bit文件或者烧写flash文件都要大半天,实在是难以忍受。逻辑分析仪看了下xilinx的下载线,速度只有6.25M,并且数据间隔非常大,不懂这线的开发者咋想的,这总线利用率真是低到爆了 上图为xilinx DLC 10下载线波形,惨不忍睹! 为了不浪费生命在下载等待时间上,我打算找找看有没有别的仿真调试选择。经过一番查找后发现Xilinx的仿真器好像选择不是很多,要么贵死要

听我瞎扯淡的博客 1万+

深入解析cnchar:强大的汉字拼音与笔画处理库

在现代Web开发中,处理汉字相关功能是一个常见需求。cnchar作为一个专业的JavaScript库,为开发者提供了强大的汉字处理能力,包括拼音转换、笔画查询等核心功能。本文将全面介绍cnchar的各项功能和使用方法,帮助开发者快速掌握这一实用工具。 ## 一、cnchar核心功能概述 cnchar库主要提供两大核心功能: 1. **汉字拼音处理**:支持获取汉字拼音、首字母、音调等功能 2...

gitblog_00187的博客 579

14、多标签分类与卷积神经网络在医学图像处理中的应用

本文探讨了多标签分类与卷积神经网络(CNN)在医学图像处理中的应用。文章详细介绍了多标签分类的概念和挑战,以及如何通过CNN进行高效、准确的分类任务。内容涵盖模型设计、损失函数选择、数据增强技术、类别权重调整等关键技术点,并结合实际案例,如白内障手术工具检测、视网膜血管分割等,展示了CNN在医学图像分析中的强大潜力。此外,还讨论了模型优化策略及面临的挑战与解决方案。

t8u9v0的博客 198

oracle数据库按中文拼音排序,以及提取中文字符串拼音首字母函数

1、Oracle9i 新增了按照拼音、部首、笔画排序功能,在使用时一般都是按拼音排序 按照拼音排序: select * from [表名]order by nlssort([栏位名],'NLS_SORT=SCHINESE_PINYIN_M'); 按照笔画排序: select * from [表名]order by nlssort([栏位名],'NLS_SORT=SCHINESE_STROKE_M'); 按照部首排序: select * from [表名] order by nlssort([栏位名],

JohnieLi的博客 2787

阿里九宫格验证码 (Baxia SecCaptcha) 逆向工程与自动化求解

实现对阿里巴夏 (Baxia) 九宫格点击验证码的全自动求解模式说明依赖浏览器模式通过 Puppeteer/Playwright 控制真实浏览器,享有完整 DOM/Canvas/WASM 环境需要 Chrome/Chromium纯算模式脱离浏览器,通过 HTTP API + Node.js WASM 解密完成求解无需浏览器。

猫敷雪 437

详解舵机的基本原理以及控制方法

文章目录什么是舵机?伺服控制硬件连接舵机规格SG90MG90SMG996R总结 什么是舵机? 舵机是伺服电机的一种,伺服电机就是带有反馈环节的电机,我们可以通过伺服电机进行精确的位置控制或者输出较高的扭矩; 舵机也叫也叫 RC 伺服器,通常用于机器人项目,也可以在遥控汽车,飞机等航模中找到它们。 类似舵机这样的伺服系统通常由小型电动机,电位计,嵌入式控制系统和变速箱组成。 电机输出轴的位置由内部电位计不断采样测量,并与微控制器(例如STM32,Arduino)设置的目标位置进行比较; 根据相应的偏差,控制

一名热爱技术的工程师的博客。分享技术干货,记录美好生活。永远相信美好的事情即将发生。 4万+

iOS--中文排序、全拼音排序

本文示例Demo在GitHub:https://github.com/gaussli/ChineseSortDemo 在做项目的时候,总遇到排序问题,英文排序是很简单的,直接使用compare方法就可以实现了,但是一旦遇到中文,就显得麻烦了。 iOS和java不同,java能进行中文字符串的比较,而iOS却没有这个功能。于是乎,iOS中的中文排序就要自己想办法了。相信很多人想到的方法就

gaussli的专栏 5521

AI穿透式智慧粮仓

本报告基于 2025-2026 年全国多地智慧粮储实践案例,系统分析了 "AI + 穿透式" 智慧粮储体系的技术架构、AI 算法应用、提质增效成效、区域差异化特点及未来发展趋势。该体系通过多模态感知、智能算法与管控平台的深度融合,实现粮食存储全流程精准感知、智能预警与科学调控,显著降低储粮损耗与运营成本,大幅提升储粮安全水平与管理效率。报告梳理了各地差异化实践路径,提出针对性发展建议,为推动我国粮食仓储高质量发展、筑牢国家粮食安全防线提供参考。

reset2021的博客 239

QT meeGo 中文字符串排序

<br /><br />本站所有文章由本站和原作者保留一切权力,仅在保留本版权信息、原文链接、原文作者的情况下允许转载,转载请勿删改原文内容, 并不得用于商业用途。 谢谢合作。原文链接:MeeGo 中文字符串排序<br /> <br />Qt类中的qSort()函数提供了对字符串的排序功能。要利用qSort为中文进行排序则需要我们提供一个针对中文比较规则的比较器。<br />Meego Touch Framework 中的MCollator实现了该功能。更准确地说是MCollator实现了所有国家语言的排序

hufeng825的专栏 1577

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Python根据拼音对中文排序

调用pypinyin库转拼音后使用sorted()即可

XerCis的博客 8462

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: FLVRetriever - 在线视频存储概述
下一篇: Self Print in C++
vbvan
博客等级 码龄19年 132粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址