11344 - The Huge One

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

Moderator: Board moderators

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 11344 - The Huge One

Post by Shihab » Fri Jun 13, 2014 8:45 am

help WA

Code: Select all

#include<cstdio>
#include<cstring>

using namespace std;

int T,i,t,sets,div[13],sum,last_digit,j,even_sum,odd_sum;

char number[2001];

int d[6] = {1,3,2,6,4,5};

bool func( int last_digit , int sum)
{
    int last_2_digits = 0,flag=0,temp,temp1,k;

    i=1;

    while( i<= sets  )
    {
        if( div[ i ] == 2)
        {
            if( number[ last_digit ] !='0' && number[ last_digit ] !='2' && number[ last_digit ] !='4' && number[ last_digit ] !='6' && number[ last_digit ] !='8' )
                return 0;
        }
        else if( div[ i ] == 3 )
        {

            if( (sum % 3) != 0 )
                return 0;
            //printf("ERROR\n");
        }
        else if( div[i] == 4 )
        {
            last_2_digits += number[ last_digit ] - '0';
            if( last_digit >= 1 )
                last_2_digits +=  ( number[ last_digit -1 ] -'0' ) * 10;

            if(  ( last_2_digits % 4 ) != 0 )
                return 0;
        }
        else if(div[i] == 5)
        {
            if( number[last_digit] !='0' && number[ last_digit ] != '5' )
                return 0;
        }

        else if( div[i] == 6 )
        {
            if( number[ last_digit ] !='0' && number[ last_digit ] !='2' && number[ last_digit ] !='4' && number[ last_digit ] !='6' && number[ last_digit ] !='8'
                    || sum % 3 != 0  )
                return 0;
        }
        else if( div[i] == 7 )
        {
            temp = 0;
            k = last_digit;
            j = 0;
            while( k>=0 )
            {
                temp += (  number[ k ] - '0' ) * d[  j  ];
                //printf("%d\n",d[j]);
                j++;
                if( j == 5)
                    j = 0;
                k--;
            }

//printf("%d\n",temp);

            if( temp % 7 != 0)
                return 0;
        }

        else if( div[i] == 8 )
        {
            last_2_digits += number[ last_digit ] -'0';
            if( last_digit >=1  )
                last_2_digits +=  ( ( number[ last_digit -1 ] -'0' ) * 10) ;
            if( last_digit >1  )
                last_2_digits +=  ( number[ last_digit - 2 ] -'0' ) * 100;
            if( last_2_digits % 8 != 0)
                return 0;
        }
        else if( div[i] == 9 )
        {
            if(sum % 9 != 0)
                return 0;
        }
        else if( div[i] == 10 )
        {
            if( number[ last_digit ] != '0')
                return 0;
        }
        else if( div[i] == 11 )
        {
            odd_sum = sum - even_sum;
            if( odd_sum > even_sum )
                temp = odd_sum- even_sum;
            else
                temp = even_sum - odd_sum;

            //printf("%d\n",sum);

            if( temp != 0 && ( temp % 11 ) != 0 )
                return 0;
        }
        else if( div[i] == 12 )
        {
            if( sum % 3 != 0 )
                return 0;
            else
            {
                last_2_digits += number[ last_digit ] - '0';
                if( last_digit >= 1 )
                    last_2_digits +=  ( number[ last_digit -1 ] -'0' ) * 10;

                if( last_2_digits % 4 != 0 )
                    return 0;
            }
        }

        i++;
    }

    return 1;

}

int main()
{
    int flag ;

    scanf("%lld\n",&T);

    for(t=0; t<T; t++)
    {

        scanf("%s",number);

        scanf("%d",&sets );

        for(i=1; i <= sets; i++)
        {
            scanf("%d",&div [ i ] );
        }

        j = sum =  even_sum = 0 ;

        while( number[ j ] != '\0' )
        {
            sum += number[ j ] - '0';
            if( j % 2 == 0)
            {
                even_sum += number[ j ] - '0';
                //printf("%d\n",j+1);
            }

            j++;
        }

        last_digit = j-1;

        //printf(" SUM = %d - LD = %d\n",sum,last_digit);

        flag = 0;

        if( sum == 0  || func( last_digit , sum )  )
        {
            printf("%s - Wonderful.\n",number);
        }
        else
            printf("%s - Simple.\n",number);

    }


    return 0;
}


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

Re: 11344 - The Huge One

Post by brianfry713 » Fri Jun 13, 2014 9:26 pm

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 113 (11300-11399)”