先上题目:

Digital Roots

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39890    Accepted Submission(s): 12286

Problem Description
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.

 
Input
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.
 
Output
For each integer in the input, output its digital root on a separate line of the output.
 
Sample Input
24
39
0
 
Sample Output
6
3
 
  题意是给你一个数字,求出它的各位数字之和,如果结果不是小于10的,就继续前面的操作,输出最后结果。
  其实这一题没有什么好说,就一个地方有点坑,明明说好了是integer,输入竟然有可能超过int,要用字符串读入才可以过= =。
 
上代码:
 
#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的更多相关文章

  1. HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

  3. HDU 1013 Digital Roots(字符串)

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  4. HDU 1013.Digital Roots【模拟或数论】【8月16】

    Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...

  5. HDU OJ Digital Roots 题目1013

     /*Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  6. HDU 1013 Digital Roots(字符串,大数,九余数定理)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. HDU 1006 Digital Roots

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  8. HDU 1013 Digital Roots 题解

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  9. hdu 1013 Digital Roots

    #include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...

随机推荐

  1. Android WiFi/WiFi热点开发总结

    首先看一下WiFi的自我介绍: Wi-Fi是一种允许电子设备连接到一个无线局域网(WLAN)的技术,通常使用2.4G UHF或5G SHF ISM 射频频段.连接到无线局域网通常是有密码保护的:但也可 ...

  2. U32670 小凯的数字 数学

    这是洛谷一个比赛中的一道题,和去年NOIP D1T1挺像.我看了一眼之后想“这不是小学奥数吗?求一个数字和就好了呀”...然后,60,剩下T了,gg. 只好看正解,但是一脸懵逼???然后看了证明,c* ...

  3. 5.27 sorm图

  4. SQLServer2008 关于数据转换

    全进位 select cast(ceiling(2.1111) as dec(18,0)) 结果:3

  5. OI知识点

  6. P3709 大爷的字符串题(50分)

    题目背景 在那遥远的西南有一所学校 /*被和谐部分*/ 然后去参加该省省选虐场 然后某蒟蒻不会做,所以也出了一个字符串题: 题目描述 给你一个字符串a,每次询问一段区间的贡献 贡献定义: 每次从这个区 ...

  7. React+Dva

    Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state Effect app.mode ...

  8. Android开发笔记(13)——ListFragment

    转载请注明:http://www.cnblogs.com/igoslly/p/6959108.html ListFragment ListFragment是继承于Fragment的类,专门用于包含Li ...

  9. SQL Server实现用户注册

    用SQL Server注册用户,通过页面输入注册信息,存储到数据库. <form action="zhuChe.jsp" method="post" on ...

  10. jQuery中容易让人困惑的东西

    前言:jqueryt很灵活,太灵活了,可以说是他一个优点,也是他一个缺点,达到一种效果,十个人也许会用十种不同的方法来实现这个过程,结果一样,过程不一样,这到底是好,还是坏呢. 一,什么是jquery ...