HDU 1013 Digital Roots
来源:互联网 发布:神盾局特工 知乎 编辑:程序博客网 时间:2024/04/29 19:10
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013
题 意:如24,找到他的各位数之和为6,若大于9,则继续计算如39得到12再到3.
思 路:找规律,每九个一个循环 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ......... 100 101 102 103 ....
0 1 2 3 4 5 6 7 8 9 1 2 3 4 .......1 2 3 4....
代码如下:
#include <iostream>using namespace std;#include <string.h>#include <stdio.h>#include <cmath>#include <algorithm>int main(){ char str[2000]; while( scanf ( "%s", str ) != EOF ) { if( str[0] == '0' ) break; int ans = 0; for( int i = 0 ; str[i] != '\0'; i ++ ) ans+=(str[i]-'0'); int p = ans%9; if( p == 0 ) printf("9\n"); else printf("%d\n",p); } return 0;}
0 0
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU--1013--Digital Roots
- hdu 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- hdu 1013 Digital Roots
- Digital Roots hdu 1013
- HDU 1013 Digital Roots
- Android 性能测试
- 博客开张之面试(2),MVC
- SQL语句的解析顺序
- iOS中代码使用Autolayout
- HDU 5310 Souvenir
- HDU 1013 Digital Roots
- shell版俄罗斯方块二:界面绘制
- iOS开发 NSArray数组的排序(系统自带的方法)
- 简单动画(僵尸快跑)
- 2.01-变量的内存分析
- hive的安装
- 02-scanf函数的基本使用
- 黑马程序员——Java基础-反射学习
- linux之sed用法