HDU 1013 Digital Roots 题解
repeated. This is continued as long as necessary to obtain a single digit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process
must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
24
39
0
6
3
水题,数位相加到剩下一位就能够了。
不须要使用大数加法。
#include <stdio.h>
#include <string>
#include <iostream>
using std::cin;
using std::string; int getRootDigit(int num)
{
int root = num;
while (root > 9)
{
root = 0;
while (num)
{
root += num % 10;
num /= 10;
}
num = root;
}
return root;
} int main()
{
string s;
while (cin>>s)
{
if (s == "0") break;
int num = 0;
for (int i = 0; i < (int)s.size(); i++)
{
num += s[i] - '0';
}
printf("%d\n", getRootDigit(num));
}
return 0;
}
HDU 1013 Digital Roots 题解的更多相关文章
- HDU 1013 Digital Roots(to_string的具体运用)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (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(字符串)
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- HDU 1013.Digital Roots【模拟或数论】【8月16】
Digital Roots Problem Description The digital root of a positive integer is found by summing the dig ...
- 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
#include <stdio.h> int main(void) { int m,i;char n[10000]; while(scanf("%s",&n)= ...
- HDU OJ Digital Roots 题目1013
/*Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1310 - Digital Roots
先上题目: Digital Roots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 杭电 1013 Digital Roots
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...
随机推荐
- 解决root登录 -bash-4.2# 的问题
- 【2017 Multi-University Training Contest - Team 3】RXD's date
[Link]: [Description] [Solution] [NumberOf WA] 1 [Reviw] [Code] #include <bits/stdc++.h> using ...
- 洛谷 P1911 L国的战斗之排兵布阵
P1911 L国的战斗之排兵布阵 题目背景 L国即将与I国发动战争!! 题目描述 L国的指挥官想让他的每一个军营都呈现出国徽形——“L”形(方向无所谓).当然,他的指挥营除外(这叫做个性),他想不出该 ...
- hdu 3294 Girls' research
#include<stdio.h> #include<string.h> #define MAX 200020 char s[MAX],ss[MAX*2],str[2]; in ...
- 源代码看CoordinatorLayout.Behavior原理
在上一篇博客CoordinatorLayout高级使用方法-自己定义Behavior中,我们介绍了怎样去自己定义一个CoordinatorLayout的Behavior.通过文章也能够看出Behavi ...
- 根证书 CA
根证书 CA 密钥没有密码,使用下面的指令添加密码 openssl rsa -aes256 -in cakey_nopw.pem -out cakey_pw.pem cacert.pem -----B ...
- Appium_pytest fixture的使用
一.定义fixture方法 # -*- coding:utf-8 -*-import pytestfrom baseutil.DriverUtil import DriverConfig @pytes ...
- Keil 编译环境之在线仿真调试问题
一.问题现象: 这几天刚开始上手STM32,使用Keil 环境进行编程,然后使用ULINK2进行在线仿真,在按键处理函数程序中设置断点,却发现按了按键程序没有停在设置的断点,程序正常运行,如下图所示, ...
- 洛谷——P1101 单词方阵
https://www.luogu.org/problem/show?pid=1101#sub 题目描述 给一nXn的字母方阵,内可能蕴含多个“yizhong”单词.单词在方阵中是沿着同一方向连续摆放 ...
- AlertDialog的onCreateDialog与onPrepareDialog用法
场景:在一个Activity中多次使用弹出对话框.而且对话框携带着动态变化的信息数据,这时假设仅仅使用onCreateDialog(int id, Bundle bundle)回调,则会发现第一次以后 ...