HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013
Digital Roots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90108 Accepted Submission(s): 28027
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.
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long LL;
int main()
{
string s;
LL sum;
while(cin>>s)
{
if(s=="")
break;
while(s.size()>)//当size==1的时候,就是答案
{
sum=;
for(int i=;i<s.size();i++)
{
sum+=(s[i]-'');//累加
}
s=to_string(sum);//转化成字符串
}
cout<<s<<endl;
}
return ;
}
HDU 1013 Digital Roots(to_string的具体运用)的更多相关文章
- 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 ...
- 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)= ...
- HDU OJ Digital Roots 题目1013
/*Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1310 - Digital Roots
先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 杭电 1013 Digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...
随机推荐
- 第八章.Java集合
Java集合类是一种特别有用的工具类,可用于存储数量不等的对象.Java集合大致可分为Set.List.Queue和Map四种体系 Set代表无序.不可重复的集合 List代表有序.重复的集合 Map ...
- laravel验证规则
就拿laravel的登入验证来举例: 1.进入login控制器, use AuthenticatesUsers;从这里点进去找到验证规则 //验证protected function validate ...
- 模块与包&常用模块
一.模块的使用 模块定义:一系列功能的集合体 分为三大类:1.自定义模块 2.内置模块(比如 time,os,sys) 3.第三方模块 模块的表现形式: 1.使用python编写的py文件 2.已被编 ...
- sql: T-SQL parent-child function script
--Parent-Child reationship --涂聚文 2014-08-25 --得位置的子節點函數表(包含本身) if exists (select * from dbo.sysobjec ...
- Angular的生命周期钩子
没有什么不能用一张图来解决.
- 点击空白处--某个div 消失
背景:1.需要在 easyui grid 的编辑框 获取焦点的时候,在正下方展示费用类型的网格 2.在点击费用类型网格以外的地方,该网格消失 思路: 一.用easyui 的panel 作为费用类型网格 ...
- Redis 实现分布式锁
前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上已经有各种介 ...
- 完整SQL分页存储过程(支持多表联接)
http://www.cnblogs.com/andiki/archive/2009/03/24/1420289.html Code/********************************* ...
- ComboBox赋值ItemsSource数据源的时候会触发SelectionChanged改变事件的解决办法
我用的方法是设置开关 bool flag = false;//默认开关关闭(全局变量) flag = false;在赋值数据源之前设置关闭box.ItemsSource = lstProperty;/ ...
- 小程序——使用Easy Mock
使用Easy Mock 一.什么是Easy Mock Easy Mock 是一个可视化的能快速生成模拟数据的持久化服务.在实际开发中常见的Mock方式一般是将模拟数据直接写在代码里,利用Java ...