30: 1, 30: 1

Source: Internet
Author: User

30: 1, 30: 1
30: 1

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Given a decimal non-negative integer N, it corresponds to the number of 1 in the binary number.

Input
The input contains a row containing a non-negative integer N. (N <1, 109)
Output
The output line contains an integer, indicating the number of 1 in the binary notation of N.
Sample Input
100
Sample output
3
Source
2709
 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cmath> 5 using namespace std; 6 int ans[10001]; 7 int now; 8 int tot; 9 int main() 10 {11     int n;12     cin>>n;13     while(n!=0)14     {15         ans[now]=n%2;16         n=n/2;17         if(ans[now]==1)18         tot++;19     }20     cout<<tot;21     return 0;22 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.