#include<iostream> #include<string.h> #include<cstdlib> using namespace std; char a[33]; int countOfZeros(int n) { int count=0; itoa(n,a,2); int len=strlen(a); //cout<<a<<" "<<len<<endl; for(int i=0;i<len;i++) if(a[i]==‘0‘) count++; return count; } int main() { int num; cin>>num; cout<<countOfZeros(num)<<endl; }
时间: 2024-10-29 19:07:24