注意:大数要用字符串表示!

sprintf:字符串格式化命令

主要功能:将格式化的数据写入某个字符串缓冲区

头文件:<stdio.h>

原型

int sprintf( char *buffer, const char *format, [ argument] … );

参数列表

bufferchar型指针,指向将要写入的字符串的缓冲区。
format:格式化字符串。
[argument]...:可选参数,可以是任何类型的数据。
 

返回值

返回写入buffer 的字符数,出错则返回-1. 如果 buffer 或 format 是空指针,且不出错而继续,函数将返回-1,并且 errno 会被设置为 EINVAL。
sprintf 返回被写入buffer 的字节数,结束字符‘\0’不计入内。即,如果“Hello”被写入空间足够大的buffer后,函数sprintf 返回5。

代码实现:

 #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的更多相关文章

  1. 【九度OJ】题目1124:Digital Roots 解题报告

    [九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...

  2. POJ 1519:Digital Roots

    Digital Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25766   Accepted: 8621 De ...

  3. HDOJ 1013题Digital Roots 大数,9余数定理

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  4. ACM1013:Digital Roots

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  5. 九度OJ 1124:Digital Roots(数根) (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2963 解决:1066 题目描述: The digital root of a positive integer is found by s ...

  6. HDU - 1310 - Digital Roots

    先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. HDU 1013 Digital Roots【字符串,水】

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 1013 Digital Roots(to_string的具体运用)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Othe ...

  9. 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 ...

随机推荐

  1. 在使用swiper时,解决同一个页面使用多个轮播出现问题做法

    $(".swiper-container").each(function(){ $(this).swiper({ loop: true, initialSlide :0, pagi ...

  2. SQL学习笔记之SQL查询练习题1

    (网络搜集) 0x00 表名和字段 –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id ...

  3. DigitalOcean(edu用户)搭建VPS

    免费上网FQ edu福利 edu邮箱 VPS VPN 1 申请 目的:利用edu邮箱的优惠获得digitalocean一年vpn,可以FQ或者免流. 1.1 准备工作 百度“github大礼包”,浏览 ...

  4. GreenOpenPaint的实现(三)添加标尺

    标尺对于图像处理程序,特别是需要精确测量的程序来说意义很大.这里进行了专门的研究. 基于现在已经引入的类和定义的变量,主要讲一讲如何调用. 1.添加放大缩小 void CGreenOpenPaintD ...

  5. 20145211黄志远《网络对抗》Exp9 Web安全基础实践

    20145211黄志远<网络对抗>Exp9 Web安全基础实践 基础问题回答 SQL注入攻击原理,如何防御? SQL注入攻击就是利用输入的机会构造自己期望的请求,比如破坏掉用户名或者密码验 ...

  6. hdu 5683 zxa and xor 暴力

    zxa and xor Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

  7. js脚本控制图片水平与垂直居中

    使用方法: 1.定义ResizeImg(obj)方法 function ResizeImg(obj) { var boxHeight = $(".box").height(); v ...

  8. Win7SDK

    1.ISO下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=8442 2.可供下载的 版本有3个,网上搜到的解释: GRMSD ...

  9. [osgearth]通过API创建一个earth模型

    通过API的方式大体需要以下几个步骤: 创建map对象—— 创建影像数据层—— 创建高程数据层—— 将影像数据层以及高程数据层加入到map对象—— 根据前面创建的map对象创建mapNode节点—— ...

  10. UVA-10129 Play on Words (判断欧拉道路的存在性)

    题目大意:给出一系列单词,当某个单词的首字母和前一个单词的尾字母相同,则这两个单词能链接起来.给出一系列单词,问是否能够连起来. 题目分析:以单词的首尾字母为点,单词为边建立有向图,便是判断图中是否存 ...