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 1104. Don’t Ask Woman about Her Age

Why do i get WA?
Posted by Alexandru Mosoi 25 Jan 2002 20:41
#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
    long int v = 0;
    long int k = 0;
    int finish = 0;

    while(!finish)
    {
    int ch = fgetc(stdin);
    if(ch != EOF)
    {
        if('0' <= ch && ch <= '9') ch = ch - 48;
        else if('A' <= ch && ch <= 'Z') ch = ch - 55;
        else ch = -1;

        if(ch != -1)
        {
        v = v + ch;
        if(ch > k) k = ch;
        } else finish = 1;

    } else finish = 1;
    }

    if(k == 0)
    {
        printf("No solution.\n");
        return 0;
    }

    for(; k < 36; k ++)
    if(v % k == 0)
    {
        printf("%ld\n", k + 1);
        return 0;
    }

    printf("No solution.\n");
    return 0;
}

This is my program. If you can find me an example that my program
won't run corectly please let me know. Thanks.
Now you'll get AC :) (+)
Posted by Miguel Angel 26 Jan 2002 01:54
Just a little change that you don't take in account. Luck!

#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
     long int v = 0;
     long int k = 1;
     int finish = 0;

     while(!finish)
     {
    int ch = fgetc(stdin);
    if(ch != EOF)
    {
         if('0' <= ch && ch <= '9') ch = ch - 48;
         else if('A' <= ch && ch <= 'Z') ch = ch - 55;
         else ch = -1;

         if(ch != -1)
         {
        v = v + ch;
        if(ch > k) k = ch;
         } else finish = 1;

    } else finish = 1;
     }

     for(; k < 36; k ++)
    if(v % k == 0)
    {
        printf("%ld\n", k + 1);
         return 0;
    }

    printf("No solution.\n");
     return 0;
}
Re: Now you'll get AC :) (+)
Posted by Alexandru Mosoi 26 Jan 2002 16:26
Thanks. I've got AC. But why should k be 1?
Your program failed with a n = 0, it returns "no solution"(-)
Posted by Miguel Angel 27 Jan 2002 02:59
> #include <stdio.h>
>
> #define max(a, b) ((a) > (b) ? (a) : (b))
>
> int main(void)
> {
>     long int v = 0;
>     long int k = 0;
>     int finish = 0;
>
>     while(!finish)
>     {
>     int ch = fgetc(stdin);
>     if(ch != EOF)
>     {
>         if('0' <= ch && ch <= '9') ch = ch - 48;
>         else if('A' <= ch && ch <= 'Z') ch = ch - 55;
>         else ch = -1;
>
>         if(ch != -1)
>         {
>         v = v + ch;
>         if(ch > k) k = ch;
>         } else finish = 1;
>
>     } else finish = 1;
>     }
>
>     if(k == 0)
>     {
>         printf("No solution.\n");
>         return 0;
>     }
>
>     for(; k < 36; k ++)
>     if(v % k == 0)
>     {
>         printf("%ld\n", k + 1);
>         return 0;
>     }
>
>     printf("No solution.\n");
>     return 0;
> }
>
> This is my program. If you can find me an example that my program
> won't run corectly please let me know. Thanks.