Re: 10922 - 2 the 9s
Posted: Wed Mar 14, 2012 7:22 pm
I have coded this prob ..bt each time getting WA...Here is my code Any one plz Help me to fix the BUG
Code: Select all
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int num(int);
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int i=0,ct=0,r,br=0,t;
char arr1[2000];
//while(a[0]!=0)
while(1)
{
ct=0;
scanf("%s",arr1);
if(arr1[0]=='0' && strlen(arr1)==1)
break;
ct=0;
t=0;
for(i=0;i<arr1[i];i++)
{
t+=arr1[i]-'0';
}
//cout<<i<<" ";
//l=a[i-1];
//cout<<l<<endl;
if(t%9!=0)
{
br=1;
ct=0;
}
r=t;
//if(br!=1)
{
while(r>=9)
{
if(r==9)
{
ct++;
break;
}
// cout<<r<<endl;
r=num(r);
// cout<<r<<endl;
ct++;
}
}
// if(a[0]!=0)
//for(k=0;k<i;k++)
printf("%s",arr1);
if(t%9==0)
printf(" is a multiple of 9 and has 9-degree %d.\n",ct);
else
printf(" is not a multiple of 9.\n");
//i=0;
}
//system("pause");
return 0;
}
int num(int s)
{
int t=0;
while(s>0)
{
t=(s%10)+t;
s=s/10;
}
return t;
}