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 1007. Code Words

Why my program got WA#1???
Posted by Pichayoot 10 Oct 2005 16:45
I think my program is correct.


sum = 0;
            fl = 0;
            for (i = len; i > 0; i--)
            {
                if (s[i] == '1')
                {
                    sum += i;
                    fp[i] = ++count;
                }
                else
                    fp[i] = count;
            }
            d = sum%(n+1);
            p = n+1-d;
            if (d == 0)
                printf("%s0\n", s);
            else if (d == 1)
                printf("%s1\n", s);
            else if (p <= count)
            {
                for (i = 1; i <= len; i++)
                {
                    if (fl == 0 && fp[i] == p)
                    {
                        printf("0");
                        fl = 1;
                    }
                    printf("%c", s[i]);
                }
            }
            else
            {
                for (i = 1; i <= len; i++)
                {
                    if (fl == 0 && fp[i]+i == p)
                    {
                        printf("1");
                        fl = 1;
                    }
                    printf("%c", s[i]);
                }
            }