九度OJ 1124 Digital Roots -- 数位拆解
题目地址:http://ac.jobdu.com/problem.php?pid=1124
- 题目描述:
-
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process
is repeated. This is continued as long as necessary to obtain a single digit.For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the
process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
- 输入:
-
The input file will contain a list of positive integers, one per line.
The end of the input will be indicated by an integer value of zero.
- 输出:
-
For each integer in the input, output its digital root on a separate line of the output.
- 样例输入:
-
24
39
0
- 样例输出:
-
6
3
- 提示:
-
The integer may consist of a large number of digits.
#include <stdio.h>
#include <string.h> void digital_roots (char data[]){
int ans;
int len;
int i; len = strlen (data);
ans = 0;
for (i=0; i<len; ++i)
ans += data[i] - '0';
i = 0;
while (ans){
data[i] = ans % 10 + '0';
ans /= 10;
++i;
}
data[i] = '\0';
} int main(void){
char input[10001]; while (scanf ("%s", input) != EOF && input[0] != '0'){
while (strlen (input) > 1){
digital_roots (input);
}
printf ("%d\n", input[0] - '0');
} return 0;
}
九度OJ 1124 Digital Roots -- 数位拆解的更多相关文章
- 九度OJ 1124:Digital Roots(数根) (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2963 解决:1066 题目描述: The digital root of a positive integer is found by s ...
- 【九度OJ】题目1124:Digital Roots 解题报告
[九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...
- 【九度OJ】题目1015:还是A+B 解题报告
[九度OJ]题目1015:还是A+B 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1015 题目描述: 读入两个小于10000的正整 ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ 1502 最大值最小化(JAVA)
题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...
- 九度OJ,题目1089:数字反转
题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...
- 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...
- 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...
- 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)
题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述: 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...
随机推荐
- 利用gdb 调试android jni c动态库
http://blog.dornea.nu/2015/07/01/debugging-android-native-shared-libraries/ Since I haven't done thi ...
- HDU5643-King's Game
BestCoder上的题,直接贴网站上的题目和题解了.很棒的题. 问题描述为了铭记历史,国王准备在阅兵的间隙玩约瑟夫游戏.它召来了 n(1≤n≤5000) 个士兵,逆时针围成一个圈,依次标号 1,2, ...
- Topology拓扑
- 有关window.location 对象
之前在有关location的使用就一种方式给他的href赋值使页面跳转.今天看项目中的代码看到了一个不一样的用法 window.location.href = 'http://' + document ...
- Spring BOOT PERFORMANCE
转自:http://www.alexecollins.com/spring-boot-performance/ 官方优化文档: https://spring.io/blog/2015/12/10/sp ...
- 点击modal确定键后删除tr
做第一个笔记,关于 “书单”.2016-09-03关于一个表格调用modal后,在点击表格中的删除按钮弹出modal,点击确定删除后,将一整行tr 删除的功能. 以下内容为table,表示为某班学生. ...
- ThinkPHP3.1新特性:Action参数绑定
Action参数绑定功能提供了URL变量和操作方法的参数绑定支持,这一功能可以使得你的操作方法定义和参数获取更加清晰,也便于跨模块调用操作方法了.这一新特性对以往的操作方法使用没有任何影响,你也可以用 ...
- java验证码(采用struts2实现)转
第一步:编写验证码的Action package com; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; ...
- careercup-数学与概率 7.6
7.6 在二维平面上,有一些点,请找出经过点数最多的那条线. 解法: 类似于leetcode:Max Points on a Line 我们只需在任意两点之间“画”一条无限长的直线(也即不是线段),并 ...
- 如何测试mysql是否安装成功
1.命令行:net start mysql如果能启动,那说明安装成功了.如果想查询默认的数据库,你可以用mysqlfont,或者直接命令行操作进入安装目录下的bin文件夹,或者配置好环境变量,然后2. ...