杭电1013-Digitai Root(这是一道考研编程题-天大2015)
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53625 Accepted Submission(s): 16747
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 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.
#include<string.h>
int main(){
long int sum,len,i;
char num[10000];
while(scanf("%s",num) && num[0]!='0'){
len=strlen(num);
sum=0;
for(i=0;i<len;i++)
sum+=num[i]-'0';
sum=sum%9;
if(sum>0)
printf("%d\n",sum%9);
else
printf("9\n");
}
return 0;
}
杭电1013-Digitai Root(这是一道考研编程题-天大2015)的更多相关文章
- 杭电 1013 Digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 4639 hehe 杭电2013多校联赛第四场1008题
解题报告:题目的意思是输入一个字符串,并规定,里面的“hehe”可以用"wqnmlgb"来代替,也可以不代替,问输入的这个字符串在经过相关的代替之后可以有多少种不同的形态.先打一个 ...
- 杭电oj1860:统计字符(字符串hash / 水题)
统计字符 题目链接 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem D ...
- 杭电OJ2039——三角形(c++)(易错题:数据类型不确定)
三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 杭电 1272 POJ 1308 小希的迷宫
这道题是我学了并查集过后做的第三个题,教我们的学姐说这是并查集的基础题,所以有必要牢牢掌握. 下面就我做这道题的经验,给大家一些建议吧!当然,我的建议不是最好的,还请各位大神指出我的错误来,我也好改正 ...
- 杭电ACM题单
杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...
- 用python爬取杭电oj的数据
暑假集训主要是在杭电oj上面刷题,白天与算法作斗争,晚上望干点自己喜欢的事情! 首先,确定要爬取哪些数据: 如上图所示,题目ID,名称,accepted,submissions,都很有用. 查看源代码 ...
随机推荐
- C# 集合-并发处理-锁OR线程
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...
- 更改Mysql数据库中的数据出现乱码问题
数据库服务器环境:windows 7 专业版 Mysql版本:5.5.36 出现问题:搭完工程之后,在做保存和插入操作时,涉及的数据在数据库中为变为乱码. 解决方案: MySQL数据库 ...
- Android Push Notification实现信息推送使用
本贴在http://www.cnblogs.com/hanyonglu/archive/2012/03/16/2399655.html下略为改动. Apndroid Push Notification ...
- Java基础(4):Scanner输入的典型应用
import java.util.Scanner; /* * 功能:为指定的成绩加分,直到分数大于等于60为止 * 输出加分前的成绩和加分后的成绩,并且统计加分的次数 * 步骤: * 1.定义一个变量 ...
- jquery 实现ajax 上传文件的功能(使用插件 ajaxfileupload)
js文件的下载地址 : http://files.cnblogs.com/wangqc/ajaxfileupload.js 页面代码: <html> <!-- 引入相关的js文 ...
- Android Notification通知栏使用
package com.example.mynotifycation; import android.app.Activity; import android.app.Notification; im ...
- CSS3 filter:drop-shadow滤镜与box-shadow区别应用 抄的
CSS3 filter:drop-shadow滤镜与box-shadow区别应用 这篇文章发布于 2016年05月18日,星期三,01:07,归类于 css相关. 阅读 5777 次, 今日 12 次 ...
- angular filter
日期格式化: <span ng-bind="topShowList.sendTime|dateFormat|date:'MM-dd HH:mm'"></span& ...
- 查看在线EBS用户的相关信息
--查看在线EBS用户的相关信息 SELECT PAP.FULL_NAME, FU.USER_NAME, FAT.APPLICATION_NAME, FRT.RESPONSIBILITY_NAME, ...
- Mysql触发器总结
触发器(trigger):监视某种情况,并触发某种操作. 触发器创建语法四要素:1.监视地点(table) 2.监视事件(insert/update/delete) 3.触发时间(after/befo ...