ZOJ 1115 Digital Roots(简单,字符串与数)

题目

//好一道水水题,可是我居然也错了那么多次,后来百度来发现是因为数据数位可能很长很长,要用字符串数组。。。

//简单
//有坑啊——数据可能很大很大,要用字符串表示!

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

 int main()
 {
     char s[1010];
     while(scanf("%s",s)!=EOF)
     {
         if(strcmp(s,"0")==0)break;
         //无论如何,加一遍之后就不会超过int了,,
         int len=strlen(s);
         int i,n=0,m=0;
         for(i=0;i<len;i++)
         {
             n+=(s[i]-‘0‘);
         }
         while(n%10!=n)
         {
             m=0;
             while(n)
             {
                 m+=(n%10);
                 n=n/10;
             }
             n=m;
         }
         printf("%d\n",n);

     }
     return 0;
 }

ZOJ 1115 Digital Roots(简单,字符串与数)

时间: 2024-08-27 02:10:38

ZOJ 1115 Digital Roots(简单,字符串与数)的相关文章

zoj 1115 Digital Roots

Digital Roots Time Limit: 2 Seconds      Memory Limit: 65536 KB Background 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 that digit is the digital root. If the resu

zju 1115 Digital roots 数字根

#include <iostream> #include <string> using namespace std; int main() { string n; while(cin>>n,n!="0") { int s=0,l=n.length(); for(int i=0;i<l;i++) s+=n[i]-'0'; while(s>9) s=s/10+s%10; cout<<s<<endl; } return

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

HDU 1013 Digital Roots(字符串,大数,九余数定理)

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

HDOJ(1013) ——Digital Roots(字符串模拟题)

Problem Description 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 that digit is the digital root. If the resulting value contains two or more digits, those digits a

HDOJ 1163 Eddy&#39;s digital Roots(简单数论)

[思路]:http://blog.csdn.net/iamskying/article/details/4738838 求解思路: 现在分析一个问题,假设将十位数为a,个位数为b的一个整数表示为ab,则推导得 ab*ab = (a*10+b)*(a*10+b) = 100*a*a+10*2*a*b+b*b 根据上式可得:root(ab*ab) = a*a+2*a*b+b*b = (a+b)*(a+b);[公式一] 同理也可证得:root(ab*ab*ab) = (a+b)*(a+b)*(a+b)

题目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 1013 Digital Roots(两种方法,求数字根)

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 67949    Accepted Submission(s): 21237 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