HDOJ-1013 Digital Roots
http://acm.hdu.edu.cn/showproblem.php?pid=1013
1.给出一个整数,求每一位上的数字之和
2.若求出的和大于1位,则对该和继续执行第1步,直至和的位数为1
注意:该整数有可能远远大于int或__int64的取值范围,所以用字符数组处理
# include <stdio.h>
# include <string.h> int main()
{
char num[100000], i;//输入整数长度可能远远超过整数范围 while(scanf("%s",num) && strcmp(num, "0"))
{
int temp = 0;
for(int i = 0; num[i] != '\0'; i++)//第一次对输入的整数求位和
temp += num[i] - '0'; while(temp >= 10)//若位和的位数大于1位 重复求位和操作
{
int t = temp;
temp = 0;
while(t > 0)
{
temp += t % 10;
t = t / 10;
}
}
printf("%d\n",temp);
} return 0;
}
HDOJ-1013 Digital Roots的更多相关文章
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 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 1013 Digital Roots(字符串,大数,九余数定理)
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电 1013 Digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...
- 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)= ...
- Problem : 1013 ( Digital Roots )
tips:分析不够仔细,白费了许多功夫.输入数据的范围,平时几乎很少考虑的,这个以后得注意.代码检查不够仔细啊,以后得注意了 #include<iostream> using namesp ...
- 解题报告:hdu1013 Digital Roots
2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer: ...
随机推荐
- 代码高亮插件Codemirror使用方法及下载
代码高亮插件Codemirror使用方法及下载 - 老男孩的日志 - 网易博客 代码高亮插件Codemirror使用方法及下载 2013-10-31 16:51:29| 分类: 默认分类 | ...
- hdu 5422 Rikka with Graph(简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- zoj 3706 Break Standard Weight(dp)
Break Standard Weight Time Limit: 2 Seconds Memory Limit: 65536 ...
- android推送-PHP(第三方推送:个推)
在项目初期,就安卓推送功能怎么做,曾经参考过例如XMPP之类的推送方法.但苦于那些是些英文档案,又没太多时间研究,所以打算采用第三方推送(个推,极光推送等),后来在美图技术老大推荐下用采用个推. PS ...
- (转载)XML Tutorial for iOS: How To Read and Write XML Documents with GDataXML
In my recent post on How To Choose the Best XML Parser for Your iPhone Project, Saliom from the comm ...
- Multithreading: How to Use the Synchronization Classes
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源) 翻译文章来源: msdn - Multithreading: How to Use t ...
- linux性能优化常用命令
作为一名linux系统管理员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行,但是由于硬件问题.软件问题.网络环境等的复杂性 和多变性,导致对系统的优化变得异常复杂,如何定位性能问题出在哪 ...
- 随着时间的推移:构造SDK路径错误(An error occurred while automatically activating bundle com.android.ide.eclipse.adt)
在进行Android应用的开发过程中,有时候在配置SDK路径的时候(Windows->Preferences->Android).会出现例如以下报错:An error occurred w ...
- 使用C++11实现无锁stack(lock-free stack)
前几篇文章,我们讨论了如何使用mutex保护数据及使用使用condition variable在多线程中进行同步.然而,使用mutex将会导致一下问题: 等待互斥锁会消耗宝贵的时间 — 有时候是很多时 ...
- DropDownList绑定数据
DDLName.DataSource = myRd;DDLName.DataTextField = "name";//要绑定的字段DDLName.DataValueField = ...