题意:求数根。

解法:一个数的数根就是mod9的值,0换成9,只是没想到给的是一个大数……只好先把每位都加起来再mod9……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long using namespace std; int main()
{
string s;
while(cin >> s)
{
if(s == "0") break;
int ans = 0;
for(int i = 0; i < s.size(); i++)
ans += s[i] - '0';
ans %= 9;
if(!ans) ans = 9;
cout << ans << endl;
}
return 0;
}

  

POJ 1519 Digital Roots的更多相关文章

  1. poj 1519 Digital Roots (计算根数字)

    一.Description The digital root of a positive integer is found by summing the digits of the integer. ...

  2. POJ 1519:Digital Roots

    Digital Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25766   Accepted: 8621 De ...

  3. Digital Roots 1013

    Digital Roots 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:456            测试通过:162 描述 T ...

  4. Eddy's digital Roots

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. 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 ...

  6. HDU 1163 Eddy's digital Roots

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. ACM——Digital Roots

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间 ...

  8. HDOJ 1163 Eddy's digital Roots(九余数定理的应用)

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  9. Eddy's digital Roots(九余数定理)

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

随机推荐

  1. 【C++基础】构造函数

    说说你对构造函数的理解? 构造函数:对象创建时,利用特定的值构造对象(不是构造类),将对象初始化(保证数据成员有初始值),是类的一个public 函数 ①   与类同名 ②   无返回值 ③   声明 ...

  2. .NET基础篇——Entity Framework 数据转换层通用类

    在实现基础的三层开发的时候,大家时常会在数据层对每个实体进行CRUD的操作,其中存在相当多的重复代码.为了减少重复代码的出现,通常都会定义一个共用类,实现相似的操作,下面为大家介绍一下Entity F ...

  3. SQL事物用法【转】

    SQL事务 一.事务概念 事务是一种机制.是一种操作序列,它包含了一组数据库操作命令,这组命令要么全部执行,要么全部不执行.因此事务是一个不可分割的工作逻辑单元.在数据库系统上执行并发操作时事务是作为 ...

  4. java基础知识回顾之java Socket学习(二)--TCP协议编程

    TCP传输(传输控制协议):TCP协议是一种面向连接的,可靠的字节流服务.当客户端和服务器端彼此交换数据前,必须先在双方之间建立一个TCP连接,之后才能进行数据的传输.它将一台主机发出的字节流无差错的 ...

  5. 在UWSGI和NGINX配合的情况下,配置个别目录上传及超时

    笨办法就是多加一个LOCATION. 然后,自定义以下类似参数 client_max_body_size uwsgi_connect_timeout uwsgi_read_timeout server ...

  6. java String 空指针异常

    如下代码中,第8行和第10行均会提示Exception in thread "main" java.lang.NullPointerException. 第12行的写法可行. im ...

  7. 【转】Windows平台SSH登录Linux并使用图形化界面

    备注:经验证本文提供的方法可行且比使用VNC简洁一些.略有修改.   [日期:2011-09-06] 来源:Linux社区  作者:tianhuadihuo   http://www.linuxidc ...

  8. JavaScript DOM编程基础精华03(动态设置,层的操作,性能问题)

    代码是否需要放置到onload中  //如果js代码需要操作页面上的元素,则将该代码放到onload里面.         //因为当页面加载完毕之后页面上才会有相关的元素 //如果js代码中没有操作 ...

  9. 57. Insert Interval

    题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if nec ...

  10. NSSize

    #import <Foundation/Foundation.h>   int main(int argc, const char * argv[]) {    @autoreleasep ...