lundi 25 juillet 2016

sherlock and the beast in C

I'm having a problem while solving this question https://www.hackerrank.com/challenges/sherlock-and-the-beast/ and able to solve only 14 test cases out of 15. I am left with Test case #14, if anybody can help me with this.

Here is my Code:

int main()
{
int t,i,j,val1=0,val2=0,a0,k,z,five=0,three=0,rem=0,div=0;
int a=5,b=3;

scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
    int n; 
    scanf("%d",&n);
    rem=n%3;
    div=n/3;
    if(n>2)
    {
    if(n==4)
        {printf("-1n");}
    if(rem==2){
        three=1;
        five=div-1;
    }
    else if(rem==1){
        three=2;
        five=div-3;
    }
    else if(rem==0)
    {
        three=0;
        five=div;
    }



    for(k=0;k<five;k++){printf("555");}
    for(z=0;z<three;z++){printf("33333");}

}
    else {printf("-1");}
    printf("n");
}
 return 0;
}

Test Case: 10 1 2 3 4 5 6 7 8 9 10

Expected Output:
-1 -1 555 -1 33333 555555 -1 55533333 555555555 3333333333

Aucun commentaire:

Enregistrer un commentaire