The_Law

Untitled

Oct 15th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <ctype.h>
  6.  
  7. enum
  8. {
  9.     BSIZE = 16
  10. };
  11.  
  12. int
  13. main(int argc, char *argv[])
  14. {
  15.     char s[BSIZE];
  16.     int sgn = 1;
  17.     unsigned long long ans = 0;
  18.     int inpt;
  19.  
  20.     while ((inpt = read(STDIN_FILENO, s, sizeof(s)))) {
  21.         if (inpt == -1) {
  22.             exit(1);
  23.         }
  24.         unsigned long long curr = 0;
  25.         int it = 0;
  26.         while (it < BSIZE) {
  27.             if ('0' <= s[it] && s[it] <= '9') {
  28.                 curr *= 10;
  29.                 curr += s[it] - '0';
  30.             }
  31.             if (s[it] == '-') {
  32.                 sgn = -1;
  33.             }
  34.             if (isspace(s[it])) {
  35.                 curr *= sgn;
  36.                 sgn = 1;
  37.                 ans += curr;
  38.                 curr = 0;
  39.             }
  40.             s[it] = 0;
  41.             ++it;
  42.         }
  43.     }
  44.  
  45.     printf("%lld\n", (long long) ans);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment