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. Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException

    一.写在前面 最近由于廖子尧忙于自己公司的事情和OkGo(一款专注于让网络请求更简单的网络框架) ,故让LZ 接替维护ImagePicker(一款支持单.多选.旋转和裁剪的图片选择器),也是处理了诸多 ...

  2. iOS开发之UIDynamic

    1.概述 什么是UIDynamic? UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架. 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象.比如:重力.弹性碰撞等现象 ...

  3. Dive in python Chapter3 实例

    def buildConnectionString(params): """Build a connection string from a dictionary Ret ...

  4. ORA-01994: GRANT failed: password file missing or disabled

    1.错误现象 SQL> grant sysdba to test;grant sysdba to test*ERROR at line 1:ORA-01994: GRANT failed: pa ...

  5. nvm安装和配置详细教程

    nvm是nodejs的版本管理工具,为什么要用nvm,你能百度到这篇文章相比是遇到不得不用的原因了,我们知道nodejs官方更新的速度非常快,有时候业务需要需要用某某版本,如果用的是msi安装,虽然安 ...

  6. PRINCE2 有级别吗?

    PRINCE2是分级别的,有基础级和专业级两个级别 Foundation基础级考试没有报考条件限制, 完全根据学员掌握知识的能力和实际工作经验 Practitioner 专业级考试不可越级 1.持有P ...

  7. linux监控流量脚本

    #!/bin/bashRx=`ifconfig eno16777736 | grep RX | grep packets | awk '{print $5}'`Tx=`ifconfig eno1677 ...

  8. 1.Maven的安装及配置

    1 Maven 介绍 Maven这个词可以翻译为“知识的积累”,也可以翻译为“专家”或“内行”.本书将介绍Maven这一跨平台的项目管理工具.作为Apache组织中的一个颇为成功的开源项目,Maven ...

  9. hdu 1757 A Simple Math Problem (构造矩阵解决递推式问题)

    题意:有一个递推式f(x) 当 x < 10    f(x) = x.当 x >= 10  f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + ...

  10. java代码打印打印杨辉三角

    郑州大学 徐峰 public class Print { void print(){ int[][] a=new int[6][6]; for(int i=0;i<a.length;i++){ ...