Page 3 of 3

Re: 10922 - 2 the 9s

Posted: Wed Mar 14, 2012 7:22 pm
by shashank.sm
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;
}

Re: 10922 - 2 the 9s

Posted: Thu Mar 15, 2012 11:35 pm
by brianfry713
Try this input:

Code: Select all

99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998
0

WA - 10922 - 2 the 9s

Posted: Sun Aug 04, 2013 3:42 pm
by shikhorroy
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;
}

Re: WA - 10922 - 2 the 9s

Posted: Wed Aug 07, 2013 2:16 am
by brianfry713
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.

Re: WA - 10922 - 2 the 9s

Posted: Thu Aug 22, 2013 8:20 pm
by shikhorroy
After correcting the spelling "multiple" still I am getting WA.... :(

Re: WA - 10922 - 2 the 9s

Posted: Thu Aug 22, 2013 11:53 pm
by brianfry713
That is now AC code.

Re: WA - 10922 - 2 the 9s

Posted: Fri Aug 23, 2013 8:42 am
by shikhorroy
Wow....I got AC.
Thanks, thanks, thanks...... :)

Re: WA - 10922 - 2 the 9s

Posted: Sat Jun 14, 2014 12:22 pm
by uDebug
Replying to follow the thread.

Why WA !!!!!!

Posted: Mon Mar 09, 2015 12:46 am
by rabbyprimoc2

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