1013:Digital Roots
注意:大数要用字符串表示!
sprintf:字符串格式化命令
主要功能:将格式化的数据写入某个字符串缓冲区
头文件:<stdio.h>
原型
参数列表
返回值
代码实现:
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std; int main()
{
/*注意:大数要用字符串表示*/
string str;
while(cin>>str && str != "")
{
while(str.length()>)
{
int sum = ;
for(int i = ;i<str.length();i++)
{
switch(str[i])
{
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
case '':
sum += ; break;
}
}
char b[];
sprintf(b,"%d",sum);
str = b;
}
cout<<str<<endl;
}
/*超时
while(1)
{
int x;
cin>>x;
int y = x;
int s = 0;
if(x==0) break;
else
{
while(y>9)
{
s += y%10;
y = y/10;
if(y<10)
{
s += y;
if(s>9)
{
y = s;
s = 0;
}
else
{
cout<<s<<endl;
}
}
}
}
}
*/
return ;
}
1013:Digital Roots的更多相关文章
- 【九度OJ】题目1124:Digital Roots 解题报告
[九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...
- POJ 1519:Digital Roots
Digital Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25766 Accepted: 8621 De ...
- HDOJ 1013题Digital Roots 大数,9余数定理
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- ACM1013:Digital Roots
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- 九度OJ 1124:Digital Roots(数根) (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2963 解决:1066 题目描述: The digital root of a positive integer is found by s ...
- HDU - 1310 - Digital Roots
先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (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(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...
- Digital Roots 分类: HDU 2015-06-19 22:56 13人阅读 评论(0) 收藏
Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
随机推荐
- eclipse恢复默认布局
eclipse恢复默认布局 Window (->Perspective ->) Reset Perspective
- C# 多线程编程第一步——理解多线程
一.进程.线程及多线程的概念 什么是多线程呢?不理解. 那什么是线程呢?说到线程就不得不说说进程.我在网上搜索也搜索了一些资料,大部分所说的进程其实是很抽象的东西.通俗的来讲,进程就是一个应用程序开始 ...
- uva10817 dijkstra
大白书P330 #include <iostream> #include <cstdio> #include <algorithm> #include <st ...
- navicat中文破解版,navicat破解版,navicat for mysql10.0.11简体中文破解版
https://blog.csdn.net/weixin_40426638/article/details/78933585 下载链接如下(里面有破解码) https://pan.baidu.com/ ...
- Tomcat java.lang.OutOfMemoryError: PermGen space error
Often time, Tomcat may hits the following java.lang.OutOfMemoryError: PermGen space error. java.lang ...
- 【运维技术】Zookeeper单机以及集群搭建教程
Zookeeper单机以及集群搭建教程 单机搭建 单机安装以及启动 安装zookeeper的前提是必须有java环境 # 选择目录进行下载安装 cd /app # 下载zk,可以去官方网站下载,自己上 ...
- mysql 触发器 trigger用法 one (简单的)
实例~~ example1: 创建表tab1 1 2 3 4 DROP TABLE IF EXISTS tab1; CREATE TABLE tab1( tab1_id varchar(11) ...
- 20145221 《Java程序设计》第三周学习总结
20145221 <Java程序设计>第三周学习总结 教材学习内容总结 第四章部分已在假期完成,详见博客: <Java程序设计>第四章-认识对象 第五章部分 何谓封装 封装实际 ...
- 2017-2018-1 JaWorld 第六、七周作业
2017-2018-1 JaWorld 第六.七周作业 修改需求规格说明书 上次的<需求规格说明书>初稿有哪些不足? 王译潇同学回答: 1. 引言和目的性考虑的不是很周全. 2. ...
- Codeforces Round #526 (Div. 1)
毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...