hdu_1013_Digital Roots(模拟)
来源:互联网 发布:mac jenkins 启动 编辑:程序博客网 时间:2024/06/02 02:58
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013
题意:给一个大数,必须用数组存储,然后求它每个位数之和,如果小于10则输出结果,如果大于10,继续求它和的每位数之和。
例如:1000个9,和为9000,9000>10,再求9000每位数上的和,结果为9,符合题意,则输出。
<span style="font-size:18px;">#include <iostream>#include <cstring>using namespace std;char num[10000];int res(int n){if(n < 10)return n;int i = 10;int total = 0;while(n/i){total += (n % i / (i / 10));i = i * 10;}total += n/(i/10);return res(total);}void f(char *n){int len = strlen(num);for(int i = 0;i < len;i++)a[i] = num[i] - 48;int total = 0;for(int i = 0;i < len;i++){total += a[i];}cout << res(total) << endl;}int main(int argc, char *argv[]){while(1){cin >> num;if(num[0] == 48)return 0;f(num);}return 0;}</span>
0 0
- hdu_1013_Digital Roots(模拟)
- HDU1013 - Digital Roots (模拟)
- HDU 1013_Digital Roots(大数&模拟)
- hdu 1013 Digital Roots(模拟 || 数论)
- HDU 1013 Digital Roots(模拟计算)
- hdu1013 Digital Roots (模拟||九余数定理)
- hdu_1013_Digital Roots_必须用高精度
- Codeforces 284A Cows and Primitive Roots [模拟题]
- HDOJ(1013) ——Digital Roots(字符串模拟题)
- HDU 1013.Digital Roots【模拟或数论】【8月16】
- HDU1013 Digital Roots 模拟&数论(我不会数论)
- Digital Roots
- Primitive roots
- Digital Roots
- Digital Roots
- Digital Roots
- ZOJ_1115_Digital Roots
- Digital Roots
- HashMap的工作原理-hashcode和equals原理的再次深入
- Linux 程序设计 第4版 陈健译 #3-#15
- GenericWritable实例
- 创业总结:创业公司怎样留人
- 用摄像头进行人脸和人眼实时检测的优化 算法
- hdu_1013_Digital Roots(模拟)
- linux内核编译
- KeyValueTextInputFormat实例
- java Heap Dump基本概念及如何获取
- Toad趣题:说真话的程序员 & 不说实话的经理
- HPU1287: HH实习 【贪心】
- java自学系列之0
- NLineInputFormat实例
- c++地址复制strcpy