1013 Digital Roots

#include<iostream>
using namespace std;
int root(int s){
 if(s<10){
  return s;
 }
 else{
  int a=s;
  int b=0;
  while(a!=0){
   b+=a%10;
   a=a/10;
  }
  root(b);
 }
}
int main(){
 int s;
 while(cin>>s&&s!=0){
  cout<<root(s)<<endl;
 }
}

/*#include <stdio.h>
int main()
{
char s[1000];
int i,sum;
while(scanf("%s",s)!=EOF)
{
      if(s[0]==‘0‘)
       {
         break;
        }
      sum=0;
   for(i=0;s[i]!=‘\0‘;i++)
    {
      sum+=s[i]-‘0‘;
    if(sum>9)
    {
     sum=sum%10+sum/10;
    }
    }
    printf("%d\n",sum);
    }
    return 0;
}*/

时间: 2024-08-02 22:49:31

1013 Digital Roots的相关文章

HDU 1013 Digital Roots

算法爱好者 HDU 1013 Digital Roots Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29353    Accepted Submission(s): 8974Problem Description The digital root of a positive integer is foun

HDU 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

HDU 1013 Digital Roots(to_string的具体运用)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1013 Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 90108    Accepted Submission(s): 28027 Problem Description The digital root of a

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): 67949    Accepted Submission(s): 21237 Problem Description The digital root of a positive integer is found by summing the digits of

HDU 1013.Digital Roots【模拟或数论】【8月16】

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,

hdu 1013 Digital Roots 用一个大水题来纪念我进入杭电前一万名

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

HDU 1013 Digital Roots(水题)

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