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

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
 
 
 #include<stdio.h>
int main()
{
long long int t;
scanf("%lld",&t);
while(t)
{
printf("%d\n",(t-)%+);
scanf("%lld",&t);
}
return ;
}

第一次的代码,没有考虑数字很大很大的情况下,所以一直是WA

下面使用字符串改进的代码,AC了

 #include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main()
{
string s;
while()
{
int m=;
cin>>s;
if(s[]-''==&&s.length()==)
break;
for(int i=;i<s.length();i++)
{
m+=s[i]-'';
}
cout<<(m-)%+<<endl;
}
}

1013 Realtime Status的更多相关文章

  1. [PHP]swoole_server几个进程的分工

    readme.md-/Users/zjh/Documents/我的文章/[PHP]swoole_server几个进程的分工 html{font-family: sans-serif;-ms-text- ...

  2. [PHP]Yii2框架的坑

    [PHP]Yii2框架的坑.md-/Users/zjh/Documents/我的文章/[PHP]Yii2框架的坑 html{font-family: sans-serif;-ms-text-size- ...

  3. [PHP]程序员技能栈

    [PHP]程序员技能栈.md-/Users/zjh/Documents/我的文章/[PHP]程序员技能栈 html{font-family: sans-serif;-ms-text-size-adju ...

  4. Color国际青年公寓

    Color国际青年公寓介绍.md-/Users/zjh/Documents html{font-family: sans-serif;-ms-text-size-adjust: 100%;-webki ...

  5. EXPDP IMPDP 知识总结

    Data Pump Export ATTACH Default: job currently in the user's schema, if there is only one Purpose(目的 ...

  6. 转贴---Performance Counter(包含最全的Windows计数器解释)

    http://support.smartbear.com/viewarticle/55773/ 这个Article中介绍了一个新工具,TestComplete,把其中涉及到性能计数器的部分摘抄出来了. ...

  7. Delphi 7生成XML

    文件格式为: Day 制1課 U12 ASSY01 Wrist 1009 0 2018/05/18 09:35:59 Day 制1課 U12 ASSY02 Wrist 1010 0 2018/05/1 ...

  8. Digital Twin 数字孪生

    GE的一个NB视频:http://v.youku.com/v_show/id_XMjk0NTMzODIyNA==.html http://www.gongkong.com/news/201701/35 ...

  9. Real-Time SQL Monitoring

    Real-Time SQL Monitoring可以在sql运行的时候监控其性能. 缺省情况下,单个sql执行花费的CPU或I/O时间超过5秒或sql并行执行的时候,Real-Time SQL Mon ...

随机推荐

  1. JDBC(上)

    1. 课程回顾 mysql加强 1)数据约束(表约束) 默认值: default 默认值 非空:   not null 唯一: unique 主键: primary key (非空+唯一) 自增长: ...

  2. 关于Tarjan(1)

    众所周知, 求有向图的强连通分量的Tarjan算法是以其发明者Robert Tarjan命名的.Robert Tarjan还发明了求双连通分量的Tarjan算法,以及求最近公共祖先(LCA)的离线Ta ...

  3. 看懂SqlServer查询计划 SQL语句优化分析

    转自 http://www.cnblogs.com/fish-li/archive/2011/06/06/2073626.html 阅读目录 开始 SQL Server 查找记录的方法 SQL Ser ...

  4. JavaScript实现

    JavaScript实现 Javascript实现虽然JavaScript和ECMAScript通常都被人们用来表达相同的含义,但JavaScript的含义却比ECMA-262中规定的要多得多.没错, ...

  5. iOS开发之iOS程序的启动过程

    程序启动的完整过程: (1)main函数 (2)UIApplicationMain * 创建UIApplication对象 * 创建UIApplication的delegate对象 (3)delega ...

  6. 用webstorm自动编译less产出css和sourcemap

    css产出sourcemap有什么用呢,可能大家要问这个问题了. 请移步这里 https://developers.google.com/chrome-developer-tools/docs/css ...

  7. 关于js参数传递矛盾新理解

    之前看了很多人的解释,说js中,函数的参数传递都是值传递中不理解. 他们无非举了两个例子 在这两个例子中,第二个例子可以看出参数是由值传递的.因为函数内对象的变化没有影响到函数外对象的变化.但是在第一 ...

  8. 前端MVC框架之 Angular

    一.什么是Angular jQuery,它属于一种类库(一系列函数的集合),以DOM为驱动核心:而Angular是一种 MVC 的前端框架,则是前端框架,以数据和逻辑为驱动核心,它有着诸多特性,最重要 ...

  9. 怎样获得PRINCE2证书?报名PRINCE2有什么条件?

    参加培训:想要获得PRINCE2资格证书,参加培训是非常必要的,正规的培训机构有获得组织认证考试的权力.光环国际全年开设prince2课程班,全国各个地区均可以选择培训及考试 选择培训机构:只有经AP ...

  10. JAVA优化建议

    前言 代码优化,一个很重要的课题.可能有些人觉得没用,一些细小的地方有什么好修改的,改与不改对于代码的运行效率有什么影响呢?这个问题我是这么考虑的,就像大海里面的鲸鱼一样,它吃一条小虾米有用吗?没用, ...