HDU - 1310 - Digital Roots
先上题目:
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39890 Accepted Submission(s): 12286
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.
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.
39
0
3
#include <cstdio>
#include <cstring> using namespace std; char s[]; int main()
{
int n,a,len;
//freopen("data.txt","r",stdin);
while()
{
scanf("%s",s);
n=;
len=strlen(s);
while(len--){n+=s[len]-'';}
if(n==) break;
while(n>=)
{
a=;
while(n){a+=n%; n/=;}
n=a;
} printf("%d\n",n);
}
return ;
}
1013
HDU - 1310 - Digital Roots的更多相关文章
- HDU 1013 Digital Roots【字符串,水】
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 1013 Digital Roots(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU OJ Digital Roots 题目1013
/*Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1006 Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- HDU 1013 Digital Roots 题解
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- hdu 1013 Digital Roots
#include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...
随机推荐
- luogu1415 拆分数列
题目大意 给出一列数字,需要你添加任意多个逗号将其拆成若干个严格递增的数.如果有多组解,则输出使得最后一个数最小的同时,字典序最大的解(即先要满足最后一个数最小:如果有多组解,则使得第一个数尽量大:如 ...
- .sh文件 编写格式
http://blog.sina.com.cn/s/blog_54f82cc201010hfz.html 介绍: 1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号# ...
- Python 45 css三种引入方式以及优先级
一:css三种引入方式 三种方式为:行间式 | 内联式 | 外联式 行间式 1.在标签头部的style属性内 2.属性值满足的是css语法 3.属性值用key:value形式赋值,value具 ...
- .net core 下Web API 技术栈
API文档工具:swagger https://www.cnblogs.com/suxinlcq/p/6757556.html https://www.cnblogs.com/danvic712/p/ ...
- 5.30dao-service-controller层,mybatis自动生成。(获取根据id主键获取指定详细数据)
获取权限详细数据:(参考) 1.controller:1.注入Servcie调用方法findConsumerById(参数是id); ...
- 改善用户体验 Web前端优化策略总结
前端是庞大的,包括HTML.CSS.Javascript.Image.Flash等等各种各样的资源.前端优化是复杂的,针对方方面面的资源都有不同的方式.那么,前端优化的目的是什么? 1. 从用户角度而 ...
- android AIDL示例代码(mark下)
1.demo结构图 2.ipcclient Book类. package com.mu.guoxw.ipcclient; import android.os.Parcel; import androi ...
- JDBC的详细使用
1.首先说一下需要用到的工具: ①我这里用的数据库是MySql5.6 ,MySql6.0开始被Oracle收购需要付费了,6.0以下版本免费. ②去Maven仓库下载JDBC的jar包 Maven仓库 ...
- 【SQL】CONNECT BY 层次化查询
层次化查询,顾名思义就是把查询结果有层次的呈现出来.层次化查询结果类似于树状结构,最顶端的是“根节点”,下面是“父节点”,没有子节点的是“叶节点”. 为了让一个或多个表具有层次关系,必须使用相关的字段 ...
- SQL语言入门
内容来源:唐成. PostgreSQL修炼之道[M]. 机械工业出版社, 2015. 此书购买链接:京东 亚马逊 SQL(Structured Query Language) 结构化查询语言 1. 语 ...