Digital Roots

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

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
 
Source
分析:很智障的题,我当时一直在想这怎么处理数字问题,没考虑这输入数字无限大的问题,sb啊,直接字符串从低到高位搞一下就好了,每一位处理即可!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(cin>>str&&str!="")
{
int num=;
for(int i=;i<str.length();i++)
{
num+=str[i]-'';
if(num>)
num=num/+num%;
}
cout<<num<<endl;
}
return ;
}

HDU 1013 Digital Roots【字符串,水】的更多相关文章

  1. HDU 1013 Digital Roots(字符串)

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

  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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  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 1013 Digital Roots 题解

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

  6. hdu 1013 Digital Roots

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

  7. HDU OJ Digital Roots 题目1013

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

  8. HDU - 1310 - Digital Roots

    先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. 杭电 1013 Digital Roots

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...

随机推荐

  1. 解决报错:IncompleteElementException: Could not find result map...

    今天遇到这样一个报错,记录一下: org.apache.ibatis.builder.IncompleteElementException: Could not find result map com ...

  2. bzoj 1486: [HNOI2009]最小圈

    Description Input Output Sample Input 4 5 1 2 5 2 3 5 3 1 5 2 4 3 4 1 3 Sample Output 3.66666667 HIN ...

  3. NET Framework 版本和依赖关系

    原文:https://docs.microsoft.com/zh-cn/dotnet/framework/migration-guide/versions-and-dependencies 每个版本的 ...

  4. grep 与 find 简单命令

    在使用linux的时候,经常会用到查找文件或者查找文本,下面介绍两个命令. grep 使用方法: // 在当前目录下递归查找class字符串 grep "string" -r . ...

  5. VC6.0 突然打不开dsw 工程文件的解决方案

    在vc编程中,经常遇到dsw工程文件无法打开,或者打开后看不到类和变量的问题.特别是把代码从一台电脑上copy到另一台电脑上以后,常常会碰到这种奇怪的问题.有时在编辑状态下也会发生成员变量或函数提示不 ...

  6. thinkinginjava学习笔记04_初始化与清理

    java沿用了c++的构造器,使用一个和类名完全一样的方法作为类的构造器,可以有多个构造器来通过不同的参数进行构造,称为重载:不仅是构造器可以重载,其他方法也一样通过不同的形参以及不同的返回值来实现重 ...

  7. rsyslogd以及日志轮替logrotate的梳理

    rsyslog 1)日志类型 auth :(authpriv) 主要与认证有关的机制,例如 login, ssh, su 等需要帐号/密码的咚咚: cron: 就是例行性工作排程 cron/at 等产 ...

  8. Python的特性(property)

    特性(property) 特性是对类的一个特定属性进行拦截,在操作这个属性时,执行特定的函数,对属性的操作进行拦截. 特性的实现 特性使用property类来实现,也可以使用property装饰器实现 ...

  9. 【Java框架型项目从入门到装逼】第六节 - 用ajax请求后台数据

    这一节我们来说一下如何用ajax提交请求? 我们先不讲ajax的原理,还是先以实战为主,看一下这个东西到底怎么用的? form表单: <!-- 采用post表单提交 --> <for ...

  10. 【Java框架型项目从入门到装逼】第四节 - 编写第一个Servlet程序

    在开始这一节之前呢,我们还需要把Tomcat配置到Eclipse中,配置的方式很简单,打开Eclipse,Window,Preferences,进入到这个页面: 将Tomcat的安装目录配置到Ecli ...