1 solutions

  • 0
    @ 2024-12-4 19:37:03

    C :

     
    #include<stdio.h>
    main(){int n,m,s;scanf("%d",&n);while(n--){scanf("%d",&m);s=0;while(m)m&=m-1,s++;printf("%d\n",s);}}        
    

    C++ :

    #include<stdio.h>
    int main()
    {
        int n,m,s,p;
        while(scanf("%d",&n)!=EOF)
        {
            while(n--)
            {
                s=0;
                scanf("%d",&m);
                for(p=0;m!=0;p++)
                {
                    s+=m%2;
                    m/=2;
                }
                printf("%d\n",s);
            }
        }
        return 0;
    }
    
    

    Pascal :

    var
      a:array [1..10000] of longint;
      b,c,d,i,j,k,n:longint;
    begin
        readln(n);
        for i:=1 to n do
        begin
        readln(b);
        repeat
            if b mod 2=1 then inc(a[i]);
            b:=b div 2;
        until(b=0);
        end;
        for i:=1 to n do
        writeln(a[i]);
    end.
    
    • 1

    Information

    ID
    2240
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    (None)
    # Submissions
    0
    Accepted
    0
    Uploaded By