UVA2037

时间:2022-01-06 19:39:42

UVA2037

#include<cstdio>
int Sum(int n)
{
int sum=0;
while(n!=0)
{
sum+=n%10;
n/=10; }
return sum;
}
void Cal(int a,int b)
{ while(a!=b)
{
if(a<b)
{ a+=Sum(a);
}
else
{
b+=Sum(b);
} }
printf("%d\n",a);
}
int main()
{
int n;
int count=1;
while(~scanf("%d",&n)&&n)
{ if(count>1)
printf("\n");
printf("Case #%d\n",count++);
int nn=Sum(n);
if(nn%9==0)
{ printf("first meets river 9 at ");
Cal(9,n);
}
else if(nn%3==0)
{ printf("first meets river 3 at ");
Cal(3,n);
}
else
{ printf("first meets river 1 at ");
Cal(1,n);
} } }

  

相关文章