jw910731

Zerojudge-e338

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