Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <ctype.h>
- enum
- {
- BSIZE = 16
- };
- int
- main(int argc, char *argv[])
- {
- char s[BSIZE];
- int sgn = 1;
- unsigned long long ans = 0;
- int inpt;
- while ((inpt = read(STDIN_FILENO, s, sizeof(s)))) {
- if (inpt == -1) {
- exit(1);
- }
- unsigned long long curr = 0;
- int it = 0;
- while (it < BSIZE) {
- if ('0' <= s[it] && s[it] <= '9') {
- curr *= 10;
- curr += s[it] - '0';
- }
- if (s[it] == '-') {
- sgn = -1;
- }
- if (isspace(s[it])) {
- curr *= sgn;
- sgn = 1;
- ans += curr;
- curr = 0;
- }
- s[it] = 0;
- ++it;
- }
- }
- printf("%lld\n", (long long) ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment