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

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. KVM入门

    KVM KVM(Kernel-based Virtual Machine)是众多虚拟化技术之一,它是Linux内核中的一个模块,该模块依赖于CPU,如果CPU支持虚拟化,那么该模块才可以被加载.KVM ...

  2. 独家揭秘,106岁的IBM靠什么完成了世纪大转型|钛度专访

    IBM大中华区董事长陈黎明 到2017年2月,陈黎明就担任IBM大中华区董事长整整两年了. 五年前,IBM历史上首位女CEO也是第9位CEO罗睿兰上任,三年前,IBM在罗睿兰的带领下以数据与分析.云. ...

  3. Dom 重绘重排

    https://juejin.im/entry/590801780ce46300617c89b8   DOM 重绘重排

  4. Linux centos7 redis安装教程

    1.下载解压 #下载至/home/install(或windows系统下载后上传) mkdir /home/install cd /home/install wget http://124.205.6 ...

  5. linux wa%过高,iostat查看io状况

    命令总结: 1. top/vmstat 发现 wa%过高,vmstat b >1: 参考文章: 1. 关于Linux系统指令 top 之 %wa 占用高,用`iostat`探个究竟 最近测试一项 ...

  6. Core Java 4

    p272~p273 1.除捕获异常外的另一种异常处理方式:将异常继续传递给方法调用者. 即:在方法首部添加throws说明符号,取代 try catch语句. 对于方法的调用者而言:要么处理异常,要么 ...

  7. 解决方案--duilib中edit获得鼠标焦点后右边框被覆盖

    用duilib做了一个登录框,用户名的输入使用的是edit控件. XML中是这样写的: <Edit name="subdomain_edit" tipvalue=" ...

  8. Cube Solution 2

  9. 前端工程化 - Yeoman

    什么是Yeoman Yeoman是一个前端构建工具.它整合了yo(yeoman).gulp/grunt和npm/bower等工具,组成了一个完整的工具集合,为前端开发提供了一套完整的解决方案. Yeo ...

  10. js 获取地址栏域名以及URL

    console.log(window.location.host) console.log(document.domain) console.log(window.location.href) con ...