Problem Type : Ad hoc
#include<stdio.h>
#include<string.h>
#define LEN 1100
int count =0;
int check(long long n)
{
int i;
if(n==9)
{
count++;
return count;
}
long int sum=0;
for(i=0; ;i++)
{
sum+=n%10;
n=n/10;
if(n==0)
{
count++;
break;
}
}
//printf("%ld\n",sum);
return check(sum);
}
int main()
{
long long int i,j,len,k,cou,sum,m;
char ch[LEN];
while(scanf("%s",&ch)&&ch)
{
if(strcmp(ch,"0")==0)
break;
len = strlen(ch);
sum=0;
m=0;
k=0;
for(i=0; i<len; i++)
{
sum = m*10 + ch[i]-48;
k+=ch[i]-48;
m = sum%9;
}
if(m==0)
{
int dept = check(k);
printf("%s is a multiple of 9 and has 9-degree %d.\n",ch,dept);
}
else
{
printf("%s is not a multiple of 9.\n",ch);
}
count=0;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#define LEN 1100
int count =0;
int check(long long n)
{
int i;
if(n==9)
{
count++;
return count;
}
long int sum=0;
for(i=0; ;i++)
{
sum+=n%10;
n=n/10;
if(n==0)
{
count++;
break;
}
}
//printf("%ld\n",sum);
return check(sum);
}
int main()
{
long long int i,j,len,k,cou,sum,m;
char ch[LEN];
while(scanf("%s",&ch)&&ch)
{
if(strcmp(ch,"0")==0)
break;
len = strlen(ch);
sum=0;
m=0;
k=0;
for(i=0; i<len; i++)
{
sum = m*10 + ch[i]-48;
k+=ch[i]-48;
m = sum%9;
}
if(m==0)
{
int dept = check(k);
printf("%s is a multiple of 9 and has 9-degree %d.\n",ch,dept);
}
else
{
printf("%s is not a multiple of 9.\n",ch);
}
count=0;
}
return 0;
}
No comments:
Post a Comment