| Revision 4253,
846 bytes
checked in by sam, 3 years ago
(diff) |
|
Fix copyright information and remove Id tag everywhere.
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * zzero - check how many bits zzuf changes in a stream of zeroes |
|---|
| 3 | * Copyright (c) 2008 Sam Hocevar <sam@hocevar.net> |
|---|
| 4 | * All Rights Reserved |
|---|
| 5 | * |
|---|
| 6 | * This program is free software. It comes without any warranty, to |
|---|
| 7 | * the extent permitted by applicable law. You can redistribute it |
|---|
| 8 | * and/or modify it under the terms of the Do What The Fuck You Want |
|---|
| 9 | * To Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 10 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | #include "config.h" |
|---|
| 14 | |
|---|
| 15 | #include <stdio.h> |
|---|
| 16 | #include <stdlib.h> |
|---|
| 17 | |
|---|
| 18 | int main(void) |
|---|
| 19 | { |
|---|
| 20 | static const int lut[16] = |
|---|
| 21 | { |
|---|
| 22 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 |
|---|
| 23 | }; |
|---|
| 24 | |
|---|
| 25 | int ones = 0, ch; |
|---|
| 26 | |
|---|
| 27 | while((ch = getc(stdin)) != EOF) |
|---|
| 28 | ones += lut[ch & 0xf] + lut[(ch >> 4) & 0xf]; |
|---|
| 29 | |
|---|
| 30 | printf("%i\n", ones); |
|---|
| 31 | |
|---|
| 32 | return EXIT_SUCCESS; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.