第7关:求数字之和

7-7 求整数的位数及各位数字之和 (15分) 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10​9​​的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> int main() { int n,a,count=0,sum=0; scanf("%d",&n); wh... 阅读详情
n = input()
a = n.split(',')
sum =0
for i in a:
    sum += eval(i)
print('请输入几个数字(用逗号分隔)sum={:.2f}'.format(sum))

本关任务:编写程序,实现如下功能:从键盘输入几个数字,用逗号分隔,求这些数字之和。要求输出结果保留2位小数。

测试输入:4,91,51,2,32
预期输出:sum=180.00
测试输入:5,1,1.51,12.3,22,100.24
预期输出:sum=142.05

[PTA]7-28 求整数的位数及各位数字之和 (15分) 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> int main() { int a,b=0,c,sum=0; scanf("%d",&a); if... 阅读详情

相关推荐

求一个整数各位数字之和

编写一个方法,计算一个整数各位数字之和,使用下面的方法头: public static int sumDigits(long n) 例如:sumDigits(234)返回9(2+3+4) 提示用户输入一个整数,然后显示这个整数所有数字的和。 package 学习; import java.util.*; public class study { public static int sumDigits(long n) { int n10=(int)n/100

Yunshangxiaohai的博客 3842

python输入逗号分隔_Python中用input不同分隔方式同时输入多个值并存入变量

一、输入后得到字符串类型1.使用一个逗号分隔输入>>> a,b=input("请输入两个数:").split(',')请输入两个数:2,3>>> print(a,b)2 3>>> print(type(a))2.使用空格分隔输入>>> a,b=input("请输入两个数:").split()请输入两个数:2 3>>> print(a,b)2 3>>> print(type(a))3.同时使用多种符...

weixin_39771351的博客 1万+

Java黑皮书课后题第6章:*6.2(求一个整数各位数字之和)编写一个方法,计算一个整数各位数字之和。使用下面的方法头:public static int sumDigits(long n)

6.2(求一个整数各位数字之和)编写一个方法,计算一个整数各位数字之和。使用下面的方法头:public static int sumDigits(long n)题目题目概述槽点代码运行示例 以上目录标题部分因为博主还不太清楚设置的语法,参数前后括号只能使用中文符 题目 题目概述 6.2(求一个整数各位数字之和)编写一个方法,计算一个整数各位数字之和。使用下面的方法头:public static int sumDigits(long n) 例如:sumDigits(234)返回 9 提示:使用求余操作符%提取

weixin_46356698的博客 3593

python 字符串 1.4 从键盘输入几个数字,用逗号分隔,求这些数字之和。

题目: 从键盘输入几个数字,用逗号分隔,求这些数字之和。程序分析: 输入的数字当作一个字符串来处理,首先分离出数字串,再转换成数值,这样就能求和代码: s = input('请输入:') b = sum(eval(s)) print('和为:%d' % b) 输出结果: -------------------------------------------------------------------------------- 请输入:1,2,3,4,5,6,7,8 和为:36 --------

zynaln的博客 1万+

求整数的位数及各位数字之和

对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> int main(){ int N,sum=0,i=0,t; scanf("%d",&N); while(N>0){ t=N%10; i++;

weixin_46928055的博客 331

拼题A基础篇 30 求整数的位数及其各位数字之和

拼题A基础篇30 7-31 求整数的位数及各位数字之和 (20分) #include<stdio.h> main() { int N, n = 0, sum = 0; scanf("%d", &N); while( N > 0 ) { sum+=N%10; N/=10; n = n + 1; } printf("%d %d", n, sum); return 0; } 反思

qq_52055885的博客 3776

从键盘输入一个用逗号隔开的数字字符串,然后将从字符串中分离出的各整数,输出各整数,并计算这些整数的和sum。例如,输入一个用逗号隔开的数字字符串:1,2,3,15,30,则输出: 1 2 3 15 3

#include<stdio.h> int main() { int sum=0,x; do { scanf("%d",&x); printf("%d “,x); sum=sum+x; } while(getchar()!=’\n’); printf(”\n"); printf(“sum=%d”,sum); return 0; }

m0_63974789的博客 5019

欧姆龙OMRON PLC之HostLink通讯协议(四)-FINS命令进阶应用与调试技巧

本文深入探讨欧姆龙OMRON PLC的HostLink通讯协议中FINS命令的进阶应用与调试技巧。文章聚焦实战排错,详细解析命令帧解剖、响应帧解读与网络抓包三大核心方法,并分享性能优化策略,如合并读写与异步设计。同时介绍了强制操作、多存储区访问等高级命令的应用场景,旨在帮助工程师高效解决现场通讯问题,提升系统稳定性与效率。

nept的博客 750

Python循环练习【第五周】

一、数列求和 1.题意 2.思路 3.代码 n = eval(input()) t = 1 sum = 0 for i in range(1,n+1): sum += i**i*t t = t*-1 print(sum) 二、数列求和【part two】 n = eval(input()) t = 1 sum = 0 i = 1 for k in range(1,n+1): if i <= 10: sum += k**i*t else:

兮于怀 2017

聚类模型-层次聚类

聚类模型 1、层次聚类 2、原型聚类-K-means 3、模型聚类-GMM 4、EM算法-LDA主题模型 5、密度聚类-DBSCAN 6、图聚类-谱聚类 一、层次聚类 一、聚类理论 ​ 一般来说,聚类是在训练样本的标签信息不知的情况下,学习样本内在的性质和规律,将有限的集合划分成ccc类。根据“方以类聚,物以群分”的思想,类内对象尽可能的相似,...

myazi 6504

实战教程:用DETR+超分辨率搞定红外小目标检测(附完整代码)

本文提供了一套完整的红外小目标检测实战方案,通过融合EDSR超分辨率技术与改进型DETR深度学习算法,有效解决了红外图像中小目标检测的难题。文章详细介绍了从环境搭建、数据预处理、模型定制(如引入EMA注意力与S2特征层)到训练调优的全流程,并附有完整代码,旨在帮助开发者将前沿算法高效落地于安防、自动驾驶等实际场景。

weixin_29057163的博客 532

求整数的位数及各位数字之和 (15 分)

7-5 求整数的位数及各位数字之和 (15 分) 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> #include<math.h> int main() ...

qq_27494201的博客 2万+

使用VS Code创建第一个Flutter工程

你可以使用任意文本编辑器结合命令行工具来开发Flutter应用。然而,我们推荐使用本文介绍的编辑器插件以获取更好的开发体验。这些插件提供了代码补全、代码高亮、widget辅助编辑等功能,以及为项目的运行和调试提供支持。推荐的开发工具有VS Code、Android Studio、IntelliJ。本文将重点介绍如何使用VS Code进行Flutter应用开发。

2501_91373349的博客 2126

7-5 求整数的位数及各位数字之和

对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> int main() { int n,i,x,sum=0; scanf("%d",&n); for(i=0;n!=0;i++) { x=n%10; sum+

qq_41994314的博客 1613

python实现RsaWithSHA256签名以及国密Sm3WithSm2签名

【代码】python实现RsaWithSHA256签名以及国密Sm3WithSm2签名。

weixin_45005677的博客 3354

【eNSP 华为模拟器】单臂路由实战:从原理到配置全解析

本文详细解析了单臂路由技术,通过华为eNSP模拟器从原理到配置进行实战教学。文章阐述了单臂路由如何利用路由器单物理接口创建多个子接口,实现不同VLAN间通信,并提供了完整的操作步骤、配置命令及排错方法,帮助网络工程师掌握这一经典网络技术。

698

python 7-8 对于给定的正整数N,求它的位数及其各位数字之和。 (15 分)

给定的正整数N,求它的位数及其各位数字之和。 输入格式: 在一行中给出1个正整数N。 输出格式: 在一行中输出正整数N的位数和各位数字之和。 输入样例: 在这里给出一组输入。例如: 20201224 输出样例: 在这里给出相应的输出。例如: 8 13 num = input() s=0 for i in num: s+=int(i) print(len(num),s) ...

普通大学生的博客 1万+

3、利用预训练卷积神经网络进行特征提取

本文介绍了如何使用预训练的卷积神经网络(如VGG16)进行图像特征提取,并将提取的特征存储在HDF5数据集中,以便后续用于机器学习模型的训练。文章详细阐述了特征提取的原理、HDF5数据格式的优势、HDF5DatasetWriter类的实现、特征提取流程的代码实现以及实际应用案例。通过该方法,可以在多种图像数据集上高效构建高精度的分类模型。

z2a3b4c5d的博客 114

c++实验1 7-4 求整数的位数及各位数字之和

7-4 求整数的位数及各位数字之和 (15 分) 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 代码如下: #include &lt;iostream&gt; using namespace std; int m...

Skyed_blue的博客 6599

FPGA信号处理系列文章——分数倍插值抽取滤波器(一)

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 FPGA信号处理系列文章——分数倍插值抽取滤波器(一)前言信号流matlab模型频谱示意图分析总结 前言 变采样率滤波器不仅仅存在整数倍插值和整数倍抽取的情况,还会存在分数倍插值抽取的情况。那这种情况下要怎么处理呢 信号流 分数倍插值抽取滤波器的信号流是什么?信号先进行插值,再进行FIR滤波,最后进行抽取 matlab模型 %signal 定点化数据输入 coeff_val_fir = importdata('fir.coe'); si

gzy0506的博客 1万+

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

7-28 求整数的位数及各位数字之和

7-28 求整数的位数及各位数字之和题目代码 题目 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10​9​​的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 代码 #include<stdio.h> int main(){ int N,n=0,sum=0;//n表示位数,sum表示各位数字之和 sc...

爱打哈气的小河马 468

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

7-28 求整数的位数及各位数字之和(15 分)

题目: 对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10910910^9的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 代码: #include &lt;stdio.h&gt; int main(){ int n, count, sum; ...

云上明月的博客 2万+

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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

7-2 求整数的位数及各位数字之和

对于给定的正整数N,求它的位数及其各位数字之和。 输入格式: 输入在一行中给出一个不超过10 ​9 ​​ 的正整数N。 输出格式: 在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。 输入样例: 321 输出样例: 3 6 #include<stdio.h> #include<math.h> int main() { int n,h=0,j=0,k; fabs(n) <= pow(10,9); scanf("%d",&n); do

Tanux的博客 2991

LeetCode:求整数的各位数字之和

/* 题目描述: 编写一个程序,输入一个整数,求出该整数的各位数字之和。 示例: Input:num=1234 Output:10(1+2+3+4) 解题思路: 这个主要是弄明白一个简单的数学问题,然后可以根据除以10求余得到每一个数字,并借助整除10; */ package main import "fmt" func digitSum(num int)(sum int){ sum=0 for num!=0{ sum+=num%10 /*得到尾部数字*/ num/=10 .

Jiangtagong的博客 1456
上一篇: 第6关:Python的标识符
下一篇: 第1关:温度转换
-阿呆-
博客等级 码龄6年 712粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-阿呆-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值