ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

This problem is quite strange!!!
Posted by Hu Jia Lie for contest 25 Apr 2003 16:03
This problem is so strange.
First is the word"?"should be"-1",otherwise you'll get WA.

Second,I have submitted 5 times the same programme(following),
but alternatively got "Crash(Access Violation)" and "Accepted".
Who knows why?



int factor[60];
int p=0;

int main()
{
    int i;
    long n;
    scanf("%ld",&n);
    if(n==0)printf("10");
    if(n==1)printf("1");
    if(n>=2)
    {
        while(1)
        {
            for(i=9;i>=2;i--)if(n%i==0)break;
            if(i>1)
            {
                n=n/i;
                p++;
                factor[p]=i;
                continue;
            }
            else break;
        }
        if(n>=10)printf("-1");
        else
        {
            for(i=p;i>=1;i--)
            {
                printf("%d",factor[i]);
            }
        }
    }
    return(0);
}
Re: This problem is quite strange!!!
Posted by bluestone 2 May 2003 15:39
> This problem is so strange.
> First is the word"?"should be"-1",otherwise you'll get WA.
>
> Second,I have submitted 5 times the same programme(following),
> but alternatively got "Crash(Access Violation)" and "Accepted".
> Who knows why?
>
>
>
> int factor[60];
> int p=0;
>
> int main()
> {
>     int i;
>     long n;
>     scanf("%ld",&n);
>     if(n==0)printf("10");
>     if(n==1)printf("1");
>     if(n>=2)
>     {
>         while(1)
>         {
>             for(i=9;i>=2;i--)if(n%i==0)break;
>             if(i>1)
>             {
>                 n=n/i;
>                 p++;
>                 factor[p]=i;
>                 continue;
>             }
>             else break;
>         }
>         if(n>=10)printf("-1");
>         else
>         {
>             for(i=p;i>=1;i--)
>             {
>                 printf("%d",factor[i]);
>             }
>         }
>     }
>     return(0);
> }

My god ,I had got many WA ,because I'd printed ?. faint!