10019 - Funny Encryption Method

#include<stdio.h>
#include<string.h>
int main()
{
    char str[100];
    int len,a,t,n,i,j,k,mod,arr[100],arr1[100],count,count1;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        a=n;
        i=0;
        count=0;
        count1=0;
        while(n>0)
        {
            mod=n%2;
            arr[i]=mod;
            if(arr[i]==1)
            {
                count++;
            }
            n=n/2;
        }
        sprintf(str,"%d",a);
        len=strlen(str);
        k=0;
        for(j=0; j<len; j++)
        {
            if(str[j]=='1')
            {
                arr1[k++]=1;
            }
            else if(str[j]=='2')
            {
                arr1[k++]=1;
            }
            else if(str[j]=='3')
            {
                arr1[k++]=1;
                arr1[k++]=1;
            }
            else if(str[j]=='4')
            {
                arr1[k++]=1;
            }
            else if(str[j]=='5')
            {
                arr1[k++]=1;
                arr1[k++]=1;
            }
            else if(str[j]=='6')
            {
                arr1[k++]=1;
                arr1[k++]=1;
            }
            else if(str[j]=='7')
            {
                arr1[k++]=1;
                arr1[k++]=1;
                arr1[k++]=1;
            }
            else if(str[j]=='8')
            {
                arr1[k++]=1;
            }
            else if(str[j]=='9')
            {
                arr1[k++]=1;
                arr1[k++]=1;
            }
        }
        for(j=0; j<k; j++)
        {
            if(arr1[j]==1)
            {
                count1++;
            }
        }
        printf("%d %d\n",count,count1);
        memset(arr,0,sizeof(arr));
        memset(arr1,0,sizeof(arr1));
        memset(str,'\0',sizeof(str));
    }
    return 0;
}

0 comments: (+add yours?)