## 10922 - 2 the 9s

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

shashank.sm
New poster
Posts: 1
Joined: Wed Mar 14, 2012 7:15 pm

### Re: 10922 - 2 the 9s

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;
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10922 - 2 the 9s

Try this input:

Code: Select all

``````99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998
0``````
Check input and AC output for thousands of problems on uDebug!

shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

### WA - 10922 - 2 the 9s

I can't find the problem....please help me......

Code: Select all

``````#include<stdio.h>
#include<string.h>
int main()
{
char str[1010];
long i, sum, length, add, count;

while(scanf("%s",str),strcmp(str,"0"))
{
sum = 0;
length = strlen(str);
for(i = 0; i < length; i++)
sum += (long)(str[i] - '0');

if(sum % 9 == 0)
{
count = 1;
while(sum != 9)
{
add = 0;
while(sum != 0)
{
add += sum%10;
sum /= 10;
}
sum = add;
count++;
}
printf("%s is a multiple of 9 and has 9-degree %ld.\n",str,count);
}
else
printf("%s is not a multiple of 9.\n",str);
}
return 0;
}
``````
Last edited by shikhorroy on Thu Aug 22, 2013 8:17 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: WA - 10922 - 2 the 9s

For input 8 you're printing:
8 is not a multple of 9.
AC output:
8 is not a multiple of 9.

You misspelled multiple.
Check input and AC output for thousands of problems on uDebug!

shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

### Re: WA - 10922 - 2 the 9s

After correcting the spelling "multiple" still I am getting WA....

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: WA - 10922 - 2 the 9s

That is now AC code.
Check input and AC output for thousands of problems on uDebug!

shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

### Re: WA - 10922 - 2 the 9s

Wow....I got AC.
Thanks, thanks, thanks......

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: WA - 10922 - 2 the 9s

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

rabbyprimoc2
New poster
Posts: 1
Joined: Mon Mar 09, 2015 12:35 am

### Why WA !!!!!!

Code: Select all

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[100000];
int i,j,k,l,n,m,sum,copy1,count1,x;
while(scanf("%s",&a)==1)
{
bool ll = false;
sum = 0;
copy1 = 0;
count1 = 0;
x= 0 ;
l = strlen(a);
if(l==1 && a[0]=='0') break;
for(i=0;i<l;i++)
sum = sum + a[i]-'0';
if(sum%9 ==0 )
{
ll = true;

}
else ll = false;
if(ll == false) printf("%s is not a multiple of 9.\n",a);
if(ll == true)
{
copy1 = sum;
//printf("%d\n",sum);

//x = sum/9;
// printf("%d\n",sum%9);
while(sum>9)
{
//sum = sum%9;
//printf("%d\n",sum%9);
x = sum / 9;
sum = x +(x%9);
//   printf("%d\n",x);
count1++;
}
printf("%s is a multiple of 9 and has 9-degree %d.\n",a,count1+1);

}
}
return 0;
}``````
Last edited by brianfry713 on Mon Mar 30, 2015 11:37 pm, edited 1 time in total.
Reason: Added code block