POJ 1519 Digital Roots

题意:求数根。

解法:一个数的数根就是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;
}

  

时间: 2024-08-07 07:04:20

POJ 1519 Digital Roots的相关文章

HDU1013 POJ1519 Digital Roots(解法三)

该问题的最佳解法是利用数论的9余数定理来计算数根.一个数的数根等于该数的9的余数,若余数为0则结果为9. 问题链接:HDU1013 POJ1519 Digital Roots.入门练习题,用C语言编写程序. 问题简述:输入若干正整数,求其数根,直到输入为0为止. 问题分析:数根是指整数的各个位的数字之和.如果其和为1位整数,则为结果:如果其和为多位整数,则再将各位数字相加,直到其和为1位数为止.这个问题的大陷阱是,没有指出整数是多少位的.即使使用unsignde long long类型,也可能会

题目1124:Digital Roots (方法超简单)

题目1124:Digital Roots 学到的新知识 求一个数各个的和可以把其%9就行,例如13%9=4 11%9=2:123%9=6: 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3819 解决:1335 题目描述: The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then

HDU 1163 Eddy&#39;s digital Roots

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5783    Accepted Submission(s): 3180 Problem Description The digital root of a positive integer is found by summing the digit

解题报告:hdu1013 Digital Roots

2017-09-07 22:02:01 writer:pprp 简单的水题,但是需要对最初的部分进行处理,防止溢出 /* @theme: hdu 1013 Digital roots @writer:pprp @begin:21:52 @end:21:59 @error:虽然是水题,但是还是需要对最初的处理,如果过大超过了int范围,就出错了 @date:2017/9/7 */ #include <bits/stdc++.h> using namespace std; int main() {

HDU 1013 Digital Roots【字符串,水】

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 79339    Accepted Submission(s): 24800 Problem Description The digital root of a positive integer is found by summing the digits of

Digital Roots

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 65092    Accepted Submission(s): 20292 Problem Description The digital root of a positive integer is found by summing the digits of

Digital Roots(杭电1013)(字符串处理)(大数)

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 50923    Accepted Submission(s): 15890 Problem Description The digital root of a positive integer is found by summing the digits of

HDU1163 Eddy&#39;s digital Roots【九余数定理】

Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4436    Accepted Submission(s): 2505 Problem Description The digital root of a positive integer is found by summing the digi

ACM——Digital Roots

http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1028 Digital Roots 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:493            测试通过:175 描述 The digital root of a positive integer is found by summing the digits of