2392: 求各位数字之和

时间限制: 1 Sec  内存限制: 128 MB

提交: 1253  解决: 292

题目描述

编写一个程序,计算任意输入的正整数的各位数字之和。(输入的位数不要超过10位。)

输入

123

输出

6

样例输入

  1. 145

样例输出

  1. 10

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. long int n,num,sum=0;;
  6. while(cin>>n)
  7. {
  8. sum=0;
  9. while(n>0)
  10. {
  11. num=n%10;
  12. n=n/10;
  13. sum=sum+num;
  14. }
  15. cout<<sum<<endl;
  16. }
  17. return 0;
  18. }

YTU 2392: 求各位数字之和的更多相关文章

  1. [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  2. 用java求一个整数各位数字之和

    /* * 用java求一个整数各位数字之和 */ public class Test02 { public static void main(String[] args) { System.out.p ...

  3. Leetcode之深度优先搜索(DFS)专题-129. 求根到叶子节点数字之和(Sum Root to Leaf Numbers)

    Leetcode之深度优先搜索(DFS)专题-129. 求根到叶子节点数字之和(Sum Root to Leaf Numbers) 深度优先搜索的解题详细介绍,点击 给定一个二叉树,它的每个结点都存放 ...

  4. Java实现 LeetCode 129 求根到叶子节点数字之和

    129. 求根到叶子节点数字之和 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字. 例如,从根到叶子节点路径 1->2->3 代表数字 12 ...

  5. 【二叉树-所有路经系列(根->叶子)】二叉树的所有路径、路径总和 II、路径总和、求根到叶子节点数字之和(DFS)

    总述 全部用DFS来做 重点一:参数的设置:为Root,路径字符串,路径List集合. 重点二:步骤: 1 节点为null 2 所有节点的操作 3 叶子结点的操作 4 非叶节点的操作 题目257. 二 ...

  6. [Swift]LeetCode129. 求根到叶子节点数字之和 | Sum Root to Leaf Numbers

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  7. [leetcode-129] 求根到叶子节点数字之和

    (1AC) 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字. 例如,从根到叶子节点路径 1->2->3 代表数字 123. 计算从根到叶子节 ...

  8. [LeetCode] 129. Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  9. C语言递归之求根到叶节点数字之和

    题目描述 给定一个二叉树,它的每个结点都存放一个 0-9 的数字,每条从根到叶子节点的路径都代表一个数字. 例如,从根到叶子节点路径 1->2->3 代表数字 123. 计算从根到叶子节点 ...

随机推荐

  1. Heritage of skywalkert

    Heritage of skywalkert skywalkert, the new legend of Beihang University ACM-ICPC Team, retired this ...

  2. LA 4728 旋转卡壳算法求凸包的最大直径

    #include<iostream> #include<cstdio> #include<cmath> #include<vector> #includ ...

  3. Codevs 2989 寻找somebody

    时间限制: 2 s 空间限制: 8000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在一个n*m的方阵中 寻找somebody的位置 有可能k不存在输出“bianta ...

  4. msp430项目编程43

    msp430综合项目---蓝牙控制直流电机调速系统43 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结

  5. Laravel 视图中的url

    <a href="{{ url('url') }}">url</a> <a href="{{ action('StudentControll ...

  6. CF 2018 Battle of Brains GYM 102062 F

    https://codeforces.com/gym/102062/attachments/download/8213/2018-battle-of-brains-en.pdf https://cod ...

  7. Oracle 12c在SQL Devolper中添加cdb和pdb连接

    Oracle 12c如果按默认流程安装的话会有一个叫orcl的cdb容器和一个叫pdborcld的pdb容器 一.连接名为orcl的cdb容器 连接名:localorcl 用户名:SYS 口令:Ora ...

  8. Windows下使用Nexus搭建Maven私服(安装)

    一.下载Nexus 下载OSS最新版:https://www.sonatype.com/download-oss-sonatype 老版本:https://support.sonatype.com/h ...

  9. Xib/Storyboard碰到不同版本的Xcode真是想死啊!

    Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/ ...

  10. [置顶] MySQL -- 创建函数(Function

    目标 如何在MySQL数据库中创建函数(Function) 语法 CREATE FUNCTION func_name ( [func_parameter] ) //括号是必须的,参数是可选的 RETU ...