修改目录结构,优化CMakeLists
This commit is contained in:
39
src/191.c
Normal file
39
src/191.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#define S2
|
||||
|
||||
int hammingWeight(int n)
|
||||
{
|
||||
#ifdef S1
|
||||
int weight = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (n & (1u << i))
|
||||
weight++;
|
||||
|
||||
return weight;
|
||||
#endif
|
||||
|
||||
#ifdef S1_O
|
||||
int weight = 0;
|
||||
while (n)
|
||||
{
|
||||
n &= n - 1;
|
||||
weight++;
|
||||
}
|
||||
|
||||
return weight++;
|
||||
#endif
|
||||
|
||||
#ifdef S2
|
||||
unsigned i = (unsigned)n;
|
||||
i = i - ((i >> 1) & 0x55555555);
|
||||
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
|
||||
i = (i + (i >> 4)) & 0x0f0f0f0f;
|
||||
i = i + (i >> 8);
|
||||
i = i + (i >> 16);
|
||||
return (int)(i & 0x3f);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user