Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

manasa loves maths solution IN C

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int val[10];
int flag = 0;
void permute(int i,int n)
    {
    int j,k,t;
    long int N;
    if(i == n)
    {
       N=0;
       for(k=0;k<=n;k++)
           N = N*10 + val[k];
       N = N % 1000;
       if(flag == 0)
           {
           if(N%8 == 0)
               flag =1;
       }
       //printf("%ld
",N);
    }
    else
        {
        for(j=i;j<=n;j++)
        {
        t=val[i];
        val[i]= val[j];
        val[j] = t;
           permute(i+1,n);
        t=val[i];
        val[i]= val[j];
        val[j] = t; 
        }
    }
}
int main() {
    int T;
    char ch[115];
    int arr[10]={0},i,j;
    long long int N;
    scanf("%d",&T); 
    while(T--)
        {
        N=0;
        for(i=0;i<10;i++)
            arr[i]=0;
        scanf("%s",ch);
        //printf("%s
",ch);
        //continue;
        for(i=0;i<strlen(ch);i++)
            {
            arr[ch[i]-48]=1;
        }
        j=0;
        for(i=0;i<10;i++)
            {
            //printf("%d ",arr[i]);
            if(arr[i] == 1)
              val[j++] = i; //N = N*10 + i;
        }
        //for(i=0;i<j;i++)
          //printf("%d ",val[i]);
       // break;
        flag = 0;
        //printf("%d
",flag);
        permute(0,j-1);
        //printf("%d
",flag);
        if(flag == 1)
            printf("YES
");
        else
            printf("NO
");
        //if(arr[0] == 1)
           // N = N*10;        
        //printf(" %lld
",N);
        //break;    
    }
    return 0;
}
Source by codensolve.wordpress.com #
 
PREVIOUS NEXT
Tagged: #manasa #loves #maths #solution #IN #C
ADD COMMENT
Topic
Name
8+5 =