C语言实验——各位数字之和排序

PX4 Gazebo仿真进阶:自定义飞机模型和地图的完整指南 本文详细介绍了如何在PX4 Gazebo仿真中自定义飞机模型和地图模型,包括文件架构解析、参数调整指南、地图定制技巧及常见问题解决方案。通过实战步骤和性能优化建议,帮助开发者高效完成复杂场景的飞行控制算法测试。 阅读详情

Problem Description
给定n个正整数,根据各位数字之和从小到大进行排序。
Input
输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。n<=10
Output
输出每组排序的结果。
Sample Input
2 1 2
3 121 10 111
0
Sample Output
1 2
10 111 121
代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int f(int n)//各位之和
{
int s=0;
    do
    {
        s=s+n%10;
        n=n/10;
    }
    while(n);
    return s;
}


void sort(int a[],int n)//冒泡排序
{
	  int i,j,t;
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(f(a[j])>f(a[j+1]))
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
}


int main()
{

	int n,i;
	int a[100];
	while(scanf("%d",&n), n)
	{
		for(i=0; i<n; i++)//输入数组
			scanf("%d",&a[i]);
		sort(a,n);//排序
		for(i=0; i<n; i++)//输出
		{
			if(i==0)
				printf("%d",a[i]);
			else
				printf(" %d",a[i]);
		}
		printf("\n");

	}

	return 0;
}


从零搭建风电场:手把手教你用WAsP+WindPRO完成风资源评估全流程 本文详细介绍了从零开始搭建风电场的全流程,重点讲解如何使用WAsP和WindPRO进行风资源评估和风场布局优化。内容包括软件配置、数据采集规范、风图谱建模实战、机组选型策略以及常见问题解决方案,帮助工程师掌握风电开发的核心技术,提升项目成功率。 阅读详情

相关推荐

基于51单片机扫地机器人(全套Proteus仿真+原理图+程序+说明书)

(内含源程序代码,原理图,仿真,讲解视频,元件清单等,【精品】值得推荐!!!扫地机器人是以单片机为主控制器。通过单片机控制小车行驶、除尘、蜂鸣。扫地机器人使用双电机驱动,以提高整车运动的平稳性;在智能车进驶过程中,采用双超声波模块实现避障。

2301_76434107的博客 1896

问题 D: C语言实验——各位数字之和排序

​ 题目描述 给定n个正整数,根据各位数字之和从小到大进行排序。 输入 输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。n<=10 输出 输出每组排序的结果。 样例输入 Copy 3 230 59 110 5 199 220 108 235 120 0 样例输出 Copy 110 230 59 120 220 108 235 199 提交 ​

lmh13075383854的博客 799

WPS JS宏实战:批量调整200个Word表格格式的避坑指南(附完整代码)

本文提供了一份详尽的WPS JS宏实战指南,针对批量调整大量Word表格格式的需求。文章深入解析了如何利用JS宏自动化设置字体、行距和边框,并重点解决了常见的“首行访问报错”等核心难题,附有可直接使用的完整代码,帮助用户显著提升文档处理效率。

weixin_29280219的博客 430

PTA-作业5(4)-统计各位数字之和是5的数

6-4 统计各位数字之和是5的数 (20分) 本题要求实现两个函数:一个函数判断给定正整数的各位数字之和是否等于5;另一个函数统计给定区间内有多少个满足上述要求的整数,并计算这些整数的和。 函数接口定义: int is( int number ); void count_sum( int a, int b ); 函数is判断number的各位数字之和是否等于5,是则返回1,否则返回0。 函数count_sum利用函数is统计给定区间[a, b]内有多少个满足上述要求(即令is返回1)的整数,并计算这些整数的

u011339832的博客 6935

手机端实时检测:YOLOv8n轻量化改进,骁龙865上35FPS,mAP+3.2%

YOLOv8n-Lite的改进不是简单的“砍通道、降分辨率”,而是结合手机端硬件特性(NPU加速、内存限制)和场景需求(小目标检测),通过“卷积拆分减少计算、通道瘦身适配内存、特征强化保留精度”的协同策略,在骁龙865上实现35FPS实时性与mAP+3.2%的双赢。该方案已在手机端AR应用中落地,支持实时手势识别、物体测量等功能,功耗比原始模型降低40%(连续检测1小时仅耗电12%)。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 726

【报错解决】OpenClaw 报错 `openclaw: command not found`:全局命令未加入系统 PATH 的深度排查与修复指南

在国产AI工具链开发中,OpenClaw作为关键命令行工具常出现command not found报错。本文深度分析该问题的根源——Linux环境变量PATH未包含用户级安装目录(~/.local/bin)。通过四种解决方案(临时PATH修改、永久配置、软链接、虚拟环境处理)和排错Checklist,揭示"命令存在却找不到"的本质是路径配置问题,特别适用于Docker/国产Linux/非root环境。文中强调理解Linux工具链机制对国产AI开发的重要性,并指出这是开发者掌握环境

博客 5383

1188-C语言实验——各位数字之和排序-JAVA

C语言实验——各位数字之和排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定n个正整数,根据各位数字之和从小到大进行排序。 Input 输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。n&lt;=10 Output 输出每...

SDCL-静默花开 656

Autosar软件组件分析及ARXML文件分析

Autosar软件组件分析及ARXML文件分析

专注汽车软件开发、AutoSAR、车载以太网、SOA、EE架构。 3602

1188C语言实验——各位数字之和排序

C语言实验——各位数字之和排序 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给定n个正整数,根据各位数字之和从小到大进行排序。 输入 输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。 输出 输

scf0920 2399

NVP6324、NVP6188、NVP6158C的区别详解

根据搜索结果,NVP6324、NVP6188、NVP6158C是Nextchip公司推出的不同型号视频处理芯片,主要区别体现在应用场景、功能特性、接口支持及封装规格等方面。如需进一步技术细节(如寄存器配置或开发支持),可参考具体型号的规格书或联系Nextchip代理商。

小灰灰的博客 3004

基于反事实的因果推理Causal inference based on counterfactuals--一万六千字文献详细解读(因果关系的推理应用)【全文总结】

基于反事实的因果推理Causal inference based on counterfactuals--一万六千字文献详细解读(因果关系的推理应用)【全文总结】---来自一位即将入学的准研一,也希望这篇文章能够激励自己不断走下去!!

qq_46044325的博客 4442

理工大学ACM平台题关于C语言1188 C语言实验——各位数字之和排序

C语言实验——各位数字之和排序 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给定n个正整数,根据各位数字之和从小到大进行排序。 输入 输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。 输出 输出每组排序的结果。 示例输入

SOHOCODE 1875

[QMT量化交易小白入门]-三十四、让deepseek分析北京炒家的首板策略后,在打板前增加了选股范围(量化python代码解析)

print(f'开始盘前选股')这行代码定义了一个名为的函数,当调用这个函数时,会首先打印出“开始盘前选股”的信息,表明选股流程正式启动。1、可根据情况增删部分条件,目前盘前选股目前可以选出140多支,比之前全市场监听带宽压力小了很多。2、还可以自行添加其他选股条件,比如换手率计算,炸板可能性检测。3、xtdata的数据是有可能缺失的,自己写策略时,有可能需要剔除,或者从第三方库校正,比如部分股票的流通股数。

木头大左的博客 2699

C语言实验:按各位数字之和排序的实现与技巧

在C语言编程学习中,排序算法是必须掌握的核心技能。实际应用中,排序关键字往往不是数据本身,而是经过计算得到的派生值,例如对整数的各位数字之和进行排序。这一需求常见于课程实验与在线判题系统,考验开发者对数字拆解(求数位和)与排序算法结合的编程能力。理解取模运算逐个分离数字的原理,并合理设计数据结构(如结构体)来维护原始数据与排序关键字之间的对应关系,是解决此类问题的关键。从经典实验题出发,深入剖析题目细节,对比多种求数位和的方法,并采用稳定的冒泡排序实现从小到大的排列,确保和值相同时保持原有输入顺序。完整代码

weixin_33462927的博客 255

深度学习工具包 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")

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

N - C语言实验 各位数字之和排序

N - C语言实验——各位数字之和排序 Description 给定n个正整数,根据各位数字之和从小到大进行排序。 Input 输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。n<=10 Output 输出每组排序的结果。 Sample Input 3 230 59 110 5 199 220 108 235 120 0 Output 110 230 59 120 220 108 235 199 ..

LanceLSf的博客 688

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

2009: C语言实验——各位数字之和排序

水题 但因为OJ后台出现错误故写一下标明

l769255844的博客 2857

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

上一篇: C语言实验——保留字母
下一篇: C语言实验——矩阵转置
Du_Chunfeng
博客等级 码龄8年 13粉丝 115原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值