有趣加密

先把输入的第一个数按十进制转化为二地址,拆开相加得出来为b1, 第二个把原先的数按十六进制,然后转化为二进制,拆开求和得出b2

#include<stdio.h>

int main(){

    int t,n,b1,b2,m;

    int a[10]={0,1,1,2,1,2,2,3,1,2};先把十六进制的转化为二进制,如3,0011.,得2

    scanf("%d",&t);

    while(t--){

    b1=b2=0; 

       scanf("%d",&n);

    m=n;

    while(m!=0)

       {b1+=m%2;

     m=m/2;

}

    while(n!=0)

    {b2+=a[n%10];

    n=n/10;               

}

  printf("%d %d\n",b1,b2);           

}

    return 0;    

} http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=960

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=960&mosmsg=Submission+received+with+ID+11322825

posted @ 2013-02-28 18:59  L kill  阅读(170)  评论(0编辑  收藏  举报