HDOJ1013 Digital Roots
2014-03-10 22:32
155 查看
原题链接
略坑的一道题。
#include <stdio.h>
char str[1000];
int f(int n){
int s = 0;
while(n){
s += n % 10;
n /= 10;
}
return s;
}
int main(){
int n, s;
while(scanf("%s", str), str[0] - '0'){
s = 0;
for(int i = 0; str[i] != '\0'; ++i)
s += str[i] - '0';
while(s > 9)
s = f(s);
printf("%d\n", s);
}
return 0;
}
略坑的一道题。
#include <stdio.h>
char str[1000];
int f(int n){
int s = 0;
while(n){
s += n % 10;
n /= 10;
}
return s;
}
int main(){
int n, s;
while(scanf("%s", str), str[0] - '0'){
s = 0;
for(int i = 0; str[i] != '\0'; ++i)
s += str[i] - '0';
while(s > 9)
s = f(s);
printf("%d\n", s);
}
return 0;
}
相关文章推荐
- HDOJ1013 Digital Roots
- HDOJ 1013题Digital Roots 大数,9余数定理
- HDOJ 1013题Digital Roots 大数,9余数定理
- HDOJ HDU 1013 Digital Roots
- HDOJ1013 Digital Roots
- HDOJ 1013 Digital Roots(大数)
- HDOJ1013 Digital Roots(高精度+数位分离求和)
- hdoj1013_Digital Roots
- HDOJ1013【Digital Roots】
- HDOJ 1013 Digital Roots
- 杭电OJ(HDOJ)1013题:Digital Roots(数值分解)
- HDOJ 1013 Digital Roots
- hdoj 1013 Digital roots (陷阱水题)
- HDOJ 1013 Digital Roots
- HDOJ - 1013 - Digital Roots(字符串、范围)
- 渣渣ACM日记——1013-Digital Roots (HDOJ)
- hdoj.1013 Digital Roots 20140728
- HDOJ 1013 Digital Roots
- HDOJ 1013 Digital Roots
- HDOJ1013 Digital Roots