void MyOutPut(char *str)
{
char *temp = str;
bool lastNum = false;
int aggr[100] = {0};
int len = 0;
int nIndex = 0;
//获取所有的数字
while(*temp)
{
if(*temp >= '0' && *temp <= '9')
{
if(!lastNum)
{
aggr[nIndex] = *temp - 48;
nIndex++;
}
else
{
aggr[nIndex - 1] = aggr[nIndex - 1] * 10 + *temp - 48;
}
lastNum = true;
}
else
{
lastNum = false;
}
*temp++;
}
//排序
for(int i = 0 ; i < nIndex; ++i)
{
for(int j = 0;j < nIndex - i - 1; ++j)
{
if(aggr[j] > aggr[j + 1])
{
int nMax = aggr[j];
aggr[j] = aggr[j + 1];
aggr[j + 1] = nMax;
}
}
}
//输出
for(int i = 0; i < nIndex - 1; i++)
{
printf("%d-", aggr[i]);
}
printf("%d", aggr[nIndex - 1]);
printf("\n");
}vc++获取char*中的数字,排序后输出
最新推荐文章于 2025-04-24 00:30:00 发布
本文介绍了一种用于从字符串中提取所有数字并进行排序输出的算法。通过遍历输入字符串,该算法能够识别数字字符,并按升序排列输出。程序逻辑清晰,适合初学者理解和实践。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
4860

被折叠的 条评论
为什么被折叠?



