Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 #include <stdio.h>
- 2 #include <ctype.h>
- 3 #include <stdbool.h>
- 4 #define BFSZ 1000000
- 5 unsigned n;
- 6 char buf[BFSZ];
- 7 size_t tail = 0;
- 8 int main(){
- 9 size_t ret;
- 10 ret = fread_unlocked(buf, sizeof *buf, BFSZ, stdin);
- 11 while(tail <= ret){
- 12 if(tail >= BFSZ){
- 13 if(feof(stdin)){
- 14 break;
- 15 }
- 16 else{
- 17 ret = fread_unlocked(buf, sizeof *buf, BFSZ, stdin);
- 18 tail = 0;
- 19 }
- 20 }
- 21 char raw = *(buf+tail); ++tail;
- 22 if(raw == ' ' || raw == '\n'){
- 23 unsigned ans = __builtin_popcount(n);
- 24 n = 0;
- 25 if(ans == 0){
- 26 putchar_unlocked('0');
- 27 }
- 28 else{
- 29 if(ans >= 10){
- 30 putchar_unlocked((ans/10)+'0');
- 31 putchar_unlocked((ans%10)+'0');
- 32 }
- 33 else{
- 34 putchar_unlocked(ans + '0');
- 35 }
- 36 }
- 37 putchar_unlocked('\n');
- 38 }
- 39 else{
- 40 if(raw >= '0' && raw <= '9'){
- 41 n = n*10 + ((raw) - '0');
- 42 }
- 43 }
- 44 }
- 45
- 46 return 0;
- 47 }
Advertisement
Add Comment
Please, Sign In to add comment