现在的位置: 首页 > 综合 > 正文

进制转换问题

2013年05月29日 ⁄ 综合 ⁄ 共 925字 ⁄ 字号 评论关闭
/*
【基础】:进制转换问题(easy)

Time Limit:1000MS  Memory Limit:65536K
Total Submit:271 Accepted:153 

Description 

 若将一个正整数n化为二进制,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数。 
例如:(13)10=(1101)2,其中1的个数为3,0的个数为1,则称此类数为A类数。 
(10)10=(1010)2,其中1的个数为2,0的个数也为2,称此类数为B类数。 
(24)10=(11000)2,其中1的个数为2,0的个数为3,则称此类数为B类数。 
程序要求:求出1-1000之中(包括1与1000),全部A、B两类数的个数。 

Input 

1000

Output 

(a.out)A、B两类数的个数

Sample Input 

Sample Output 

Source 

*/

#include <stdio.h>

int main(void)
{
    
int i,j,a=0,b=0,mod,ta=0,tb=0;
    
    
for(i=1 ; i<= 1000 ; i++)
    {
            j 
= i ;
            a 
= 0 ;
            b 
= 0 ;
            
while(j != 0)
            {
                   mod 
= j%2 ;
                   j 
/= 2 ;
                   
if( mod == 1)
                   a 
++ ;
                   
else
                   b 
++ ;
            }
            
if ( a > b )
            ta 
++ ;
            
else
            tb 
++ ;
    }
    
    printf(
"%d %d ",ta,tb);
    system(
"pause");
    
return 0 ;
}

 

抱歉!评论已关闭.