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 ...
随机推荐
- 在使用swiper时,解决同一个页面使用多个轮播出现问题做法
$(".swiper-container").each(function(){ $(this).swiper({ loop: true, initialSlide :0, pagi ...
- SQL学习笔记之SQL查询练习题1
(网络搜集) 0x00 表名和字段 –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id ...
- DigitalOcean(edu用户)搭建VPS
免费上网FQ edu福利 edu邮箱 VPS VPN 1 申请 目的:利用edu邮箱的优惠获得digitalocean一年vpn,可以FQ或者免流. 1.1 准备工作 百度“github大礼包”,浏览 ...
- GreenOpenPaint的实现(三)添加标尺
标尺对于图像处理程序,特别是需要精确测量的程序来说意义很大.这里进行了专门的研究. 基于现在已经引入的类和定义的变量,主要讲一讲如何调用. 1.添加放大缩小 void CGreenOpenPaintD ...
- 20145211黄志远《网络对抗》Exp9 Web安全基础实践
20145211黄志远<网络对抗>Exp9 Web安全基础实践 基础问题回答 SQL注入攻击原理,如何防御? SQL注入攻击就是利用输入的机会构造自己期望的请求,比如破坏掉用户名或者密码验 ...
- hdu 5683 zxa and xor 暴力
zxa and xor Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- js脚本控制图片水平与垂直居中
使用方法: 1.定义ResizeImg(obj)方法 function ResizeImg(obj) { var boxHeight = $(".box").height(); v ...
- Win7SDK
1.ISO下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=8442 2.可供下载的 版本有3个,网上搜到的解释: GRMSD ...
- [osgearth]通过API创建一个earth模型
通过API的方式大体需要以下几个步骤: 创建map对象—— 创建影像数据层—— 创建高程数据层—— 将影像数据层以及高程数据层加入到map对象—— 根据前面创建的map对象创建mapNode节点—— ...
- UVA-10129 Play on Words (判断欧拉道路的存在性)
题目大意:给出一系列单词,当某个单词的首字母和前一个单词的尾字母相同,则这两个单词能链接起来.给出一系列单词,问是否能够连起来. 题目分析:以单词的首尾字母为点,单词为边建立有向图,便是判断图中是否存 ...