HDOJ 1013

//wa的代码,既然说是整数,应该不用考虑大数,可实际上却要考虑大数

 

#include<stdio.h>

int main()

{

int num,temp;

while(scanf("%d",&num),num)

{

temp=num%9;

printf("%d\n",temp);

}

return 0;

}

//或者mod9,若是k,则各个数字和为k

 

//既然说是整数,应该不用考虑大数,可实际上却要考虑大数

 

/*超时代码

#include<stdio.h>

int count_digit(int num)

{

int sum=0,p=1;

while(p)

{

p=num%10;

sum+=p;

p=num/10;

}

return sum;

}

int main()

{

int num,ans;int temp;

while(scanf("%d",&num),num)

{

temp=count_digit(num);

if(temp>=10)

temp=count_digit(temp);

printf("%d\n",temp);

}

return 0;

}*/

 

 

 

 

 

 

 

 

 

 

 

//AC

 

#include<stdio.h>

#include<string.h>

#define MAX 10000

char a[MAX];

void count(int n)

{

    int tem,sum=0;

    while(n!=0)

    {

        sum+=n%10;

        n/=10;

    }

    if(sum<10)

    {

        printf("%d\n",sum);

    }

    else

    {

        count(sum);//这样便不必用goto

    }

}

int main()

{

    int i,num,len;

    while(scanf("%s",a)&&a[0]!='0')

    {

        num=0;

        len=strlen(a);

        for(i=0;i<len;i++)

        {

            num+=(a[i]-'0');

        }

        count(num);

    }        

    return 0;

}

 

 

 

 

 

 

 

 

//程序停止,因为str为指针,未指向确定空间,需要分配一个很大的空间

#include<stdio.h>

#include<string.h>

int main()

{

char *str;

int i;int len,sum=0,ans; 

//不能char str,这是单字符,否则subscript(下标) requires array or pointer type

while(scanf("%s",str),str[0]!='0')

//刚开始,多加了取地址符,结果程序停止工作

{

//getchar();

len=strlen(str);

for(i=0;i<len;i++)

sum+=str[i]-'0';

ans=sum%9;

printf("%d\n",ans);

}

return 0;

}

/*程序停止工作,提交会TLE

1.可能递归没有出口

2.scanf中未加取地址符,或者多加了取地址符

3.引用了未经初始化的内存*/

 

 

 

 

 

 

 

 

 

 

 

 

 

#include<stdio.h>

#include<string.h>

#define N 10000

char str[N];

int main()

{

int i;int len,sum,ans; 

//不能char str,这是单字符,否则subscript(下标) requires array or pointer type

while(scanf("%s",str),str[0]!='0')

//刚开始,多加了取地址符,结果程序停止工作

{

//getchar();

len=strlen(str);

sum=0;//需放在while内部

for(i=0;i<len;i++)

sum+=str[i]-'0';

ans=sum%9;

printf("%d\n",ans);

}

return 0;

}

时间: 2024-07-31 18:42:18

HDOJ 1013的相关文章

HDOJ 1013题Digital Roots 大数,9余数定理

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

DVNEWS 3.2 1013版免虚拟目录的安装方法,只要三个步骤

虚拟目录 以下操作,在W2K3 E文版,IIS 6,免虚拟目录测试通过,解决了一部份虚拟主机用户创建不了虚拟目录,或者把DVNEWS放在根目录因大量文件存在而管理麻烦的问题. 1.首先将DVNEWS/BIN目录COPY到网站根目录 2.将DVNEWS/web.config文件作以下修改 <RewriterRule> <LookFor>~/换成你的DVNEWS目录/c(\d{1,8})\.aspx</LookFor> <SendTo>~/换成你的DVNEWS目

解决苹果刷机时1601错误1013错误等的方法

我们在刷机的时候我们会遇到各式各样的错误,如:3194错误.1031错误.160X错误等等,这些错误时常让我们很烦恼.今天三联教程给大家分享下如何解决这些问题,相信大家看完之后,遇到同样的问题都会解决的. iOS系统错误集合:iTunes 中的警告信息可能还包括(但不限于)以下编号之一:2.4.5.6.9.13.14.-18.19.20.21.23.28.29.-48.-50. 1002.1004.1011.1013.1014.1015.1601.1602.1603.1604.1608.1609

最大匹配-HDOJ 2458 Kindergarten

HDOJ 2458 Kindergarten Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids 

最大匹配-HDOJ 1068

HDOJ 1068 Girls and Boys . Problem Description the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study

hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬

问题描述 hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬 #include"stdio.h" #include"math.h" int main() { int n,i,j; double s; while(scanf("%d",&n)&&n) { double a[100000][5]={0}; for(i=0;i<n;i++) for(j=0;j<2;j++) sca

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ 1164 Eddy&amp;#39;s research I(拆分成素数因子)

Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to h