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 ...
随机推荐
- Sql Server查询同一ID 时间较大的一条数据
- link标签 rel="stylesheet"
首先,link标签是用于当前文档引用外部文档的,其次,这个标签的rel属性用于设置对象和链接目的间的关系,说白了就是指明你链进来的对象是个什么东西的,具体的值及其所表示的关系如下:Alternate: ...
- python webdriver 测试框架-数据驱动DDT的例子
先在cmd环境 运行 pip install ddt 安装数据驱动ddt模块 脚本: #encoding=utf-8 from selenium import webdriver import un ...
- Example解析
本文总结自:https://github.com/abel533/Mapper/wiki/6.example,旨在提供一些基本概念上的解释 Example类用于条件查询,以代替冗长的"sel ...
- 对OpenCV中seamlessClone的初步实验
seamlessClone是OpenCV中新出现的函数,应该说如果能够基于较为准确的图像分割,能够得到很好的结果. 原始的前景,背景 三种flag下的融合结果 //注意头文件中添加 #inclu ...
- 在JAVA可移植性的来源的三方面
软件可移植性的概念是与软件从某一环境转移到另一环境下的难易程度.为获得较高的可移植性,在设计过程中常采用通用的程序设计语言和运行支撑环境.尽量不用与系统的底层相关性强的语言.下面介绍JAVA的可移植性 ...
- HDU - 3068 最长回文(马拉车Manacher)题解
思路:马拉车裸题,我们用一个p[i]数组代表以i为中心的最大回文半径.这里用了一个小技巧,如果一个串是aaaa这样的,那我们插入不相干的字符使它成为#a#a#a#a#,这样无论这个串是奇数还是偶数都会 ...
- CCNA学习指南 -开放最短路径优先OSPF(单区域)
在上个世纪九十年代撰写的<TCP/IP协议详解 卷一:协议>的动态选路中,内容大部分还是介绍 RIP路由选择信息协议,在互联网络如此发达的今天,RIP因为它的局限性逐步被OSPF取代. 在 ...
- Pro Git读书笔记 - Git 常用命令
在工作目录中初始化新仓库 要对现有的某个项目开始用 Git 管理,只需到此项目所在的目录,执行git init 检查当前文件状态 要查看哪些文件处于什么状态,可以用git status命令 将工作文件 ...
- shell 交互式选择(select)
新建文件 sudo vi test.sh 写入如下内容: #!/bin/bash echo "What is your favourite OS?" select var in & ...